Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

linking a .lib in a project

Status
Not open for further replies.

woliwol

Programmer
Mar 20, 2001
16
CA
Hi!

This looks like a school case.

I am working with Borland C++ 5.02. I have an external lib file and its associated dll version, and a header file declaring all the exported functions. I have a project in which I call a function from the lib. I want this function to be linked statically.

Right now I only get "unresolved external ..." message, but this is because the linker doesn't know in which lib to look for the function definitions.

How do I tell the linker that he'll find the missing external definition in this particular lib?

Thanks,

Woliwol



 
use the pragma statement

#pragma comment(lib, "PATH")

Eg:- If I want to link ddraw.lib using Borland compiler which is in my F: drvie I do
#pragma comment(lib, "F:\dx5sdk\sdk\lib\borland\ddraw.lib)

Now compile.

Thats all
 
Hi!

Thank you very much. I didn't know that trick. In my case, it didn't work but I think it is because my lib file is in fact an import lib, not an object lib (no source code inside). Then it raises the next question: if you have a DLL file, how do you turn it into an +object+ lib?

Thanks to the FAQS database at community.borland.com I found a partial answer to my own question and I post it here in case somebody else needs the info.

To link the project at least to the DLL version of my library (my initial question was static linking):

1) I need to declare the functions with the special format:

extern "C"
int __declspec(dllexport) WINAPI MyFunc1(int arg);

(in the case of a function of type int MyFunc1(int), to be adapted to your case).

The extern "C" seems to be crucial.


2) In my project, I need to add a .DEF node, and to add an IMPORTS section inside the .def file:

IMPORTS
MYDLL.MyFunc1
MYDLL.MyFunc2
...

(where MYDLL is the name of the particular DLL where MyFunc1 is coded).


Once you know the trick, you can easily link your program to any DLL. But before you learn it, you can easily spend hours staring at your "unresolved external ..." error messages!

Woliwol
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top