Solved

Static libraries

Posted on 2001-06-08
8
246 Views
Last Modified: 2013-12-14
Hello,

I have 2 different static libraries and an executable (let's call them A.lib and B.lib and test.exe). Test.exe calls a function in B.lib that must calls another function in A.lib (test.exe -> B.lib -> A.lib). The problem is a linker error (LNK2001: unresolved external symbol in B.lib) when building test.exe. Is there a way to tell the linker that this missing symbol is in A.lib? I'm using Visual C++ 6.0 and no MFC.

Thanks!
0
Comment
Question by:adnrwin
  • 4
  • 3
8 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 300 total points
ID: 6167980
There are two options

- add A.lib to your project

- instruct the linker to use A.lib using a '#pragma' directive, e.g.

#pragma comment ( lib, "c:\\path\\A.lib")

Feel free to ask if you need more information!
0
 

Author Comment

by:adnrwin
ID: 6168878
You're absolutely right, but it don't resolve my problem. The source of the problem is that B.lib is written in C and A.lib in C++. If you have an answer I'll double the points or in the other case I'll give you the 100 points.
Note that test.exe is an C++ app.

Thanks
0
 

Author Comment

by:adnrwin
ID: 6168879
You're absolutely right, but it don't resolve my problem. The source of the problem is that B.lib is written in C and A.lib in C++. If you have an answer I'll double the points or in the other case I'll give you the 100 points.
Note that test.exe is an C++ app.

Thanks
0
 

Author Comment

by:adnrwin
ID: 6168884
Sorry for the 2 answers. There was an internal server error when submitting.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 86

Expert Comment

by:jkr
ID: 6168902
Ahh, I think I got your problem now - I assume that you wrote both the static libraries. C++ uses name-namgling to decorate function names so the linker can distinguish between overloaded functions. In order to make that work with C code, you have to declare the functions to be used as

extern "C" a_func_thats_not_to_be_decorated();

The easiest way to do that is in your header file, e.g.

#ifdef __cplusplus
extern "C"
{
#endif
a_func_thats_not_to_be_decorated();
#ifdef __cplusplus
}
#endif


That will export the function in a way the linker can recognize it...
0
 
LVL 30

Expert Comment

by:Axter
ID: 6169154
I'm not sure if this is your situation.

If you have the code for A.lib, and B.lib, you could do the following:
Warning: Backup your project before trying this!!!

Open Test.exe project.
On the main menu, click "Project", then click "Insert Project Into Workspace".
Select project A
Then do the same for project B.

Now on the main menu, click "Project", then "Dependencies".
Select the "Test.exe" project in the "Select Project to Modify" field.
Make "Test.exe" project dependent on A and B project.
Now select "B" project, and make it dependent on "A" project.

This will force the compiler to compile in a certain order, and hold off dependent code.
0
 

Author Comment

by:adnrwin
ID: 6169366
JKR: That's it! I give you a bonus of 100pts. This is friday!

AXTER: I've also tried your proposition and it don't work. That's really a problem of name-namgling.

Thanks to both of you.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6169462
Thanx! :o)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now