User forums > Using Code::Blocks
[SOLVED] Using a DLL
TheLastArrived:
Hello all,
I don't know if this is the right place so I apologize if it's not.
I've to write an application that uses function from a dll but when I try to build a
--- Code: ---undefined reference to `_Z11TOpenDesignllPKcP10DbxContext@16'|
--- End code ---
error message appears.
I've tried to tell C::B where to find the function but without success.
Any hints?
thomas:
Too little information, but these are general things that can go wrong:
1. Name mangling may bite you if you use C++. Most DLLs export C functions, try using extern "C". Unless you forgot to link the library, this is the most common cause of symbol-related problems.
2. You should add the import library (if you use MinGW you can also direcly link to a DLL) to the linker's "link library" field
3. Name rape may affect you if you have Windows headers or something similarly abusive (wxWidgets) included. Sometimes, you will find stuff like #define new or #define GetMessage in such headers. Unlikely in your case, but something to always consider.
TheLastArrived:
Thank you for helping.
Let's try to be less vague.
I've to write an interface to a program, the program vendor gives a DLL and a header file to develop interface applications (too bad the vendor is no more accessible so no support available).
I create a std new wxWidget program, I include the header file then I use a function of the DLL (TOpenDesign) in event handler and I get
--- Code: ----------------- Build: Debug in DBXProva02 ---------------
Linking executable: bin\Debug\DBXProva02.exe
obj\Debug\DBXProva02Main.o: In function `ZN15DBXProva02Frame9OnNewFileER20wxFileDirPickerEvent':
D:/Sources/SCE/DBX Utilities/DBXProva02/DBXProva02Main.cpp:81: undefined reference to `_Z11TOpenDesignllPKcP10DbxContext@16'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings
--- End code ---
Quite right, there is no reference to libraries, so I add the dll to "link libraries" list, retry building an get
--- Code: ---Linking executable: bin\Debug\DBXProva02.exe
D:\Programmi\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lDbx32.dll
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings
--- End code ---
It seems that the dll is built (and to be used) with MS VC++ (i'm using MinGW compiler) so I'm trying using pexports, dlltool and other tool to create an import library but I got no success yet.
There is something I'm missing?
thomas:
--- Quote ---It seems that the dll is built (and to be used) with MS VC++ (i'm using MinGW compiler) so I'm trying using pexports
--- End quote ---
That works, but shouldn't even be necessary. I always link to MSVC DLLs directly, works every time.
--- Quote ---Linking executable: bin\Debug\DBXProva02.exe
D:\Programmi\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lDbx32.dll
--- End quote ---
It can't find the library. Try giving it an absolute path (or project root relative), if nothing else helps.
MortenMacFly:
--- Quote from: TheLastArrived on May 13, 2008, 12:08:25 pm ---There is something I'm missing?
--- End quote ---
Enabling the full compiler log might help (see my sig).This may give you some more hints, e.g. a missing / wrong include path for the linker (not the compiler!).
Navigation
[0] Message Index
[#] Next page
Go to full version