Solved

Static libraries

Posted on 2001-06-08
8
248 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixing C++ & C# in Vis Studio 2013 7 140
FMX enumerated colours 2 84
Header Errors LNK2019, LNK1120 - Unresolved Externals 4 91
Angular JS Route 3 45
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…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
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…

914 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

18 Experts available now in Live!

Get 1:1 Help Now