Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / September 2004

Tip: Looking for answers? Try searching our database.

Usage of static library in C

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bauerwo<at>gmx.net - 23 Aug 2004 08:15 GMT
Dear all

I'm a newbie to C, C++, and Visual C++ .Net, so if there is a better place
to ask this question, please let me know.

Using Visual C++ .Net, I haven compiled and linked a static library
"myLib.lib", providing the function "myFunc". I can access it without any
problem in another C++ program "myMain" by writing

       extern double myFunc(int N);
       pragma comment(lib,"myLib.lib")

But the goal would be to have the calling program be written in C; when I
change the project properties into /TC "Compile as C program", I get

myMain error LNK2019: unresolved external symbol _myFunc referenced in
function _main

What's the right way to include a library into C?

Best regards,

W. Bauer
David Lowndes - 23 Aug 2004 09:48 GMT
>Using Visual C++ .Net, I haven compiled and linked a static library
>"myLib.lib", providing the function "myFunc". I can access it without any
[quoted text clipped - 9 lines]
>
>What's the right way to include a library into C?

The library function needs to be defined as "C" linkage - see the help
on extern - "Using extern to Specify Linkage".

Dave
Signature

MVP VC++ FAQ: http://www.mvps.org/vcfaq

bauerwo<at>gmx.net - 29 Aug 2004 18:18 GMT
> The library function needs to be defined as "C" linkage - see the help
> on extern - "Using extern to Specify Linkage".

I suppose this is required when a C library is to be used in C++. But I
would like to use in a C program a library that has been written in C++. Is
this possible?

Many thanks, W. Bauer
Ronald Laeremans [MSFT] - 30 Aug 2004 23:16 GMT
Only if it exports C functions or if you are willing to get the C code to
compile as C++ (which in general is quite a realistic effort, even for a
relatively large code base).

Ronald Laeremans
Visual C++ team

>> The library function needs to be defined as "C" linkage - see the help
>> on extern - "Using extern to Specify Linkage".
[quoted text clipped - 5 lines]
>
> Many thanks, W. Bauer
bauerwo<at>gmx.net - 01 Sep 2004 20:37 GMT
> Only if it exports C functions or if you are willing to get the C code
> to compile as C++ (which in general is quite a realistic effort, even
> for a relatively large code base).

Many thanks, now I got it; functions in a dll can be exported and thus be
made accessible by C, super!

Best regards, W. Bauer

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.