Solved

Static libraries

Posted on 2001-06-08
8
258 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 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
Independent Software Vendors: 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!

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ question 3 81
sorting efficency of sorting algorithm 30 149
trigs fail! I thought I knew how to do trignometry 3 92
Angular JS Route 3 121
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql 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…

737 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