User forums > Using Code::Blocks
Linking to a DLL
AndreasL:
Hi!
I'm trying to utalize functionallity from a Win32 DLL in my Code::Blocks C++ program.
I have .dll, .lib and .h-file and API documentation, and that's all I've got. The DLL is once built with MFC and the source code is not available. Is this possible to link an Extension DLL (MFC) from an application not build with VisualStuio? (My aim is to use a free alternative to Vicious Studio, and Code::Blocks have topped all my expectations!)
With the .h file I can compile my sw, but when coming to the linker, I get the error code undefined reference to `DLL_Func1(long)'. Not suprisingly, the linker cannot fins the symbols.
I have tried to add the .lib file in Project Build Options, Linker Settings, Linked Libraries but it does not make any difference.
I'm running Win XP and Code::Blocks 10.05.
(I have not used the LoadLibrary and GetProcAddress methods, I was kind of hoping that I could use it as any functions via standard function calls to keep the code simple.)
Best Regards,
Andreas Lundgren
oBFusCATed:
If I remember correctly you need to convert the .lib file to .a file, search the net for info how to do it.
If the dll's interface uses MFC classes, probably you should link you app to the MFC libs and I don't know if this is possible with MinGW.
stahta01:
@Andreas Lundgren:
The compiler and its version is what?
Tim S.
AndreasL:
Hi!
I have stepped a few step back now. I create one "Dynamic Link Library" and one "Console application" project using the GNU C++ compiler.
I build the auto generated setup in the "Dynamic Link Library"-project with the one change that I rename the "main.h" to "main_dll.h". I now have exported a function called "SomeFunction". I can access this function from Matlab.
How do I access this from my "Console application"-project in Code::Blocks???
(Is there any documentation about how to set this up?)
I have no idéa about where to start. I have of course included the main_dll.h in my console application I does compile, bot from Linker I get "undefined reference to `_imp__SomeFunction". I guess I need to take more actions, any tip about what (or even better, where can I read about it?)
This is my "Console application":
--- Code: ---#include <iostream>
#include "main_dll.h"
using namespace std;
int main()
{
cout << "Hello world!" << endl;
SomeFunction("Andreas hej!");
return 0;
}
--- End code ---
stahta01:
I do NOT see a Code::Blocks question in your Question.
MinGW Compiler Link; try to write a question that is a Code::Blocks Question NOT a compile Question that has nothing to do with IDE.
http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs
Note: You can also link directly to an C (NOT C++) only DLL using MinGW; but, I am not sure what limits there is on this.
CB Example doing this is here
http://wiki.codeblocks.org/index.php?title=Linking_the_plugin_to_a_Nightly_Build#Step_Four_-_Link_Everything_Together
Tim S.
Navigation
[0] Message Index
[#] Next page
Go to full version