[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Static libraries

Posted on 2001-06-08
8
Medium Priority
?
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

650 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