?
Solved

Static libraries

Posted on 2001-06-08
8
Medium Priority
?
278 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 1200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:adnrwin
ID: 6168884
Sorry for the 2 answers. There was an internal server error when submitting.
0
 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

807 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