Linking to dll

Started by
7 comments, last by Eric_B 20 years, 3 months ago
How do I link to a dll in vc++? I''ve a dll and it''s .lib file. I''ve the header files, but when I compile its giving me this error "error LNK2001: unresolved external symbol" thanks in advance
Advertisement
I''ve added the .lib file in object/library modules on the link tab, but I''m not sure if I did it correctly or not.

include the header,
include the .lib either in the treeview in MSVC6 (if you are using it) or over project -> settings -> linker -> (mmherm..) "additional modules" or something like this, was the option IIRC - if you choose the latter you hvae to copy the .lib file to the compiler''s lib directory, so you are workdesktop-independent - if you choose the first, you have a static path included for your .lib file in your project - but both ways will work.
put the DLL either in \system32 or in your application''s directory or in another directory where you have set a systempath on.

DJSnow
---
this post is manually created and therefore legally valid without a signature
DJSnow---this post is manually created and therefore legally valid without a signature
I don''t know why it''s not working. I have all the header files in one directory, I''ve put dll and .lib file in the same directory, and added the .lib file in the treeview
header file should the same as compile time header for the dll or it needs some changes?
What is the rest of the error message... What is the Unresolved External?

If you are getting Link errors, I would say that you are not exporting the class or functions correctly. Everything may be there, but the information that the linker needs to pull out is not there.

You can either use a handcoded .def file when you build the dll or can do it this way:

(Include this in one place where other class that need to be exported/imported can get to)

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */

Then for each class that needs to be exported:

class DLLIMPORT CSprite
{
...
};

Just make sure that BUILDING_DLL (or whatever you want to name that) is defined when you build the dll, that way the exports are setup correctly. When you include the headers in a different project that needs this dll, it will setup correctly for importing.

If you cannot build the dll (if you don't have the source), you might have to try dynamic linking, and get the addresses of the functions yourself.

[edited by - pjcast on January 4, 2004 3:44:22 PM]
I''ve the source code, it''s open source gnu code, but I want to keep that code as external dll. It has a .def file but the VC++ doesn''t see the functions.... here the error unresolved external symbol: "struct LPX * __cdecl glp_lpx_create_prob(void)" (?glp_lpx_create_prob@@YAPAULPX@@XZ)
You should make sure that function is listed in the def file. Or add it to the def file, or you can use the DLLIMPORT macro technique I mentioned earlier... IN either case it involves making the changes to the dll and rebuilding it. For more info on export/import check out msdn here

[edited by - pjcast on January 4, 2004 6:15:07 PM]

This topic is closed to new replies.

Advertisement