DLL with gpp
-
- CodeLite Curious
- Posts: 6
- Joined: Sun Jan 03, 2010 4:00 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
DLL with gpp
Hello Eran,
Thanks for your nice work.
I have used to work with CodeBlocks IDE and could build DLL shared library with MINGW tools (CodeBlocks provides a template/example for that).
With Codelite, I could only build an so file.
I can see that a dll can be built with VC tool chain.
Where can I find any information or hints for how this can be done with MINGW tools. ?
Thanks for your nice work.
I have used to work with CodeBlocks IDE and could build DLL shared library with MINGW tools (CodeBlocks provides a template/example for that).
With Codelite, I could only build an so file.
I can see that a dll can be built with VC tool chain.
Where can I find any information or hints for how this can be done with MINGW tools. ?
- eranif
- CodeLite Plugin
- Posts: 6375
- Joined: Wed Feb 06, 2008 9:29 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: DLL with gpp
To make DLL:
- Use the 'Dynamic Library' template from the 'New Project' dialog
- When the project is created, rename the .so (from project settings -> General tab) to .dll
Eran
- Use the 'Dynamic Library' template from the 'New Project' dialog
- When the project is created, rename the .so (from project settings -> General tab) to .dll
Eran
Make sure you have read the HOW TO POST thread
-
- CodeLite Curious
- Posts: 6
- Joined: Sun Jan 03, 2010 4:00 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: DLL with gpp
Hi again
I have tried this with the template h,cpp files generated by CodeBlocls for a "Dynamic Linked Library".
I am getting a dll file but I can't load it with my external application (a module can not be found).
I have tried this with the template h,cpp files generated by CodeBlocls for a "Dynamic Linked Library".
I am getting a dll file but I can't load it with my external application (a module can not be found).
- eranif
- CodeLite Plugin
- Posts: 6375
- Joined: Wed Feb 06, 2008 9:29 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: DLL with gpp
I dont know what codeblocks generates in the code - so I cant help younitnit wrote:I have tried this with the template h,cpp files generated by CodeBlocls for a "Dynamic Linked Library".
I am getting a dll file but I can't load it with my external application (a module can not be found).
Try posting here the DLL code + the loading code.
How do you load the DLL? are u using dlopen? or linking it directly?
Eran
Make sure you have read the HOW TO POST thread
-
- CodeLite Curious
- Posts: 6
- Joined: Sun Jan 03, 2010 4:00 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: DLL with gpp
Hi Eran
Listed hereafter are the simple header and source templates generated by CodeBlocks.
I have tried both:
#define BUILD_DLL at the beginning of source code
and
setting BUILD_DLL in Project Settings>Compiler tab>Preprocessor
to enforce #define DLL_EXPORT __declspec(dllexport) in the header file
Actually I have not written any loading code since I am using a programing environment which can load dlls and provide interface to the loaded dlls.
The programing environments is Matlab, and when trying to load the dll, the loading function terminates with an error identified by the string
"The specified module could not be found".
It works fine with the dll compiled by CodeBlocks/Mingw.
The files are:
**************************
Header file main.h
**************************
#ifndef __MAIN_H__
#define __MAIN_H__
#include <windows.h>
/* To use this exported function of dll, include this header
* in your project.
*/
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C"
{
#endif
void DLL_EXPORT SomeFunction(const LPCSTR sometext);
#ifdef __cplusplus
}
#endif
#endif // __MAIN_H__
**************************
source file main.cpp
**************************
#include "main.h"
// a sample exported function
void DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
// attach to process
// return FALSE to fail DLL load
break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
return TRUE; // succesful
}
Listed hereafter are the simple header and source templates generated by CodeBlocks.
I have tried both:
#define BUILD_DLL at the beginning of source code
and
setting BUILD_DLL in Project Settings>Compiler tab>Preprocessor
to enforce #define DLL_EXPORT __declspec(dllexport) in the header file
Actually I have not written any loading code since I am using a programing environment which can load dlls and provide interface to the loaded dlls.
The programing environments is Matlab, and when trying to load the dll, the loading function terminates with an error identified by the string
"The specified module could not be found".
It works fine with the dll compiled by CodeBlocks/Mingw.
The files are:
**************************
Header file main.h
**************************
#ifndef __MAIN_H__
#define __MAIN_H__
#include <windows.h>
/* To use this exported function of dll, include this header
* in your project.
*/
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C"
{
#endif
void DLL_EXPORT SomeFunction(const LPCSTR sometext);
#ifdef __cplusplus
}
#endif
#endif // __MAIN_H__
**************************
source file main.cpp
**************************
#include "main.h"
// a sample exported function
void DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
// attach to process
// return FALSE to fail DLL load
break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
return TRUE; // succesful
}
- eranif
- CodeLite Plugin
- Posts: 6375
- Joined: Wed Feb 06, 2008 9:29 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: DLL with gpp
Since I never compiled such DLLs (with WinMain...) the best option for you is to compare the build lines from what codelite produces and the output from codeblocks
Eran
Eran
Make sure you have read the HOW TO POST thread
-
- CodeLite Curious
- Posts: 6
- Joined: Sun Jan 03, 2010 4:00 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: DLL with gpp
It is not easy to explore CodeBlocks build lines since they are not printed or logged. I have tried a plugin which converts the project file to a make file and there is one link parameter missing there that Codelite uses:
-fPIC
I am not sure if that cause the problem but I can't find this parameter setting in any of Codelite project or global settings.
Can you help by telling how can I remove this parameter from Codelite build lines ?
-fPIC
I am not sure if that cause the problem but I can't find this parameter setting in any of Codelite project or global settings.
Can you help by telling how can I remove this parameter from Codelite build lines ?
- eranif
- CodeLite Plugin
- Posts: 6375
- Joined: Wed Feb 06, 2008 9:29 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: DLL with gpp
select your compiler from
settings > build settings > compiler
select your compiler (g++?)
from the 'tools' page, remove the -fPIC from the 'Compiler' / Linker entry
Eran
settings > build settings > compiler
select your compiler (g++?)
from the 'tools' page, remove the -fPIC from the 'Compiler' / Linker entry
Eran
Make sure you have read the HOW TO POST thread
-
- CodeLite Curious
- Posts: 6
- Joined: Sun Jan 03, 2010 4:00 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: DLL with gpp
I have experimented with compiling and linking my dll by running mingw32-g++.exe directly from a windows cmd console and found out that when using Codelite switches (as reported in Build window), but running mingw32-g++.exe which I have installed for CodeBlocks which is version MinGW 3.4.5, I can load the target dll and call its exported functions.
When running mingw32-g++.exe from MinGW-4.4.0 (installed by recent Codelite), I am getting the the problem I have reported.
Therefor, I assume that I should downgrade MinGW used by Codelite the version 3.4.5.
However, I have installed recent Codelite+MinGW bundle and do not find how can I change the MinGW it uses. In Settings>Build Settings>Compilers>gnu g++>Tools - I can't find a way to change what "g++" is using.
I have tried adding the path of MinGW ver 3.4.5 installed for CodeBlocks as described in "Installing MinGW / gdb on Winodws" in the first post of this forum but it seems that the installed bundle still founds MinGW-4.4.0 in its path !
Do you have any hint how can I change the MinGW installation which recent Codelite use ?
When running mingw32-g++.exe from MinGW-4.4.0 (installed by recent Codelite), I am getting the the problem I have reported.
Therefor, I assume that I should downgrade MinGW used by Codelite the version 3.4.5.
However, I have installed recent Codelite+MinGW bundle and do not find how can I change the MinGW it uses. In Settings>Build Settings>Compilers>gnu g++>Tools - I can't find a way to change what "g++" is using.
I have tried adding the path of MinGW ver 3.4.5 installed for CodeBlocks as described in "Installing MinGW / gdb on Winodws" in the first post of this forum but it seems that the installed bundle still founds MinGW-4.4.0 in its path !
Do you have any hint how can I change the MinGW installation which recent Codelite use ?
- eranif
- CodeLite Plugin
- Posts: 6375
- Joined: Wed Feb 06, 2008 9:29 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: DLL with gpp
Make sure you have read the HOW TO POST thread