473,395 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Usage of static library in C

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
Nov 17 '05 #1
6 975
>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?


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

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Nov 17 '05 #2
David Lowndes <da****@example.invalid> wrote in
news:6m********************************@4ax.com:
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
Nov 17 '05 #3
David Lowndes <da****@example.invalid> wrote in
news:6m********************************@4ax.com:
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
Nov 17 '05 #4
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

"bauerwo gmx.net" <at> wrote in message
news:Xn*****************************@195.186.4.29. ..
David Lowndes <da****@example.invalid> wrote in
news:6m********************************@4ax.com:
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

Nov 17 '05 #5
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

"bauerwo gmx.net" <at> wrote in message
news:Xn*****************************@195.186.4.29. ..
David Lowndes <da****@example.invalid> wrote in
news:6m********************************@4ax.com:
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

Nov 17 '05 #6
"Ronald Laeremans [MSFT]" <ro*****@online.microsoft.com> wrote in
news:O5*************@TK2MSFTNGP11.phx.gbl:
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
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
72
by: Robin Tucker | last post by:
I need to find some documents/research for my manager about VB.NET v C# use. I've noticed that there are many more people using C# than VB.NET, that there seem to be more job vacancies specifying...
11
by: Paulo Eduardo | last post by:
Hi, All! We are developing one app for windows 95/98/Me/NT4.0/2000/XP/2003 using Visual C++ 6.0. We need to set the % of CPU Usage to app process. Is there an API to set % of CPU Usage? Can...
2
by: Jack | last post by:
I have a chunk of code that loads a few dozen function pointers into global variables. I'm concerned with unused memory consumption. What if the client only needs to use one or two functions? Then...
5
by: Sek | last post by:
hi folks, i have a bunch of strings used in my code in many places. these strings reside inside a instantiable class. so, i want to replace these with constant/static variable to control the...
5
by: Jesper Schmidt | last post by:
When does CLR performs initialization of static variables in a class library? (1) when the class library is loaded (2) when a static variable is first referenced (3) when... It seems that...
7
by: twang090 | last post by:
I find in other team member's project, they are referencing a type in following format " public static global::ErrorReport.Description Description = new global::ErrorReport.Description(); " I...
104
by: jayapal | last post by:
Hi all, Whenever I use the gets() function, the gnu c compiler gives a warning that it is dangerous to use gets(). why...? regards, jayapal.
2
by: =?Utf-8?B?dXJrZWM=?= | last post by:
I am trying to create an in-process WMI provider using System.Management.Instrumentation namespace. For testing I use a simple class as a wrapper for FileInfo class. I have been able to use all...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.