Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

linking a .lib in a project

linking a .lib in a project

linking a .lib in a project


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?



RE: linking a .lib in a project

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

RE: linking a .lib in a project

A typo - it is
#pragma comment(lib, "PATH")

I fogot to close the quote.

RE: linking a .lib in a project


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:

(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!


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close