create and use a dll
-
- CodeLite Curious
- Posts: 6
- Joined: Thu Sep 29, 2011 3:51 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
create and use a dll
Hello all,
I am very new to Codelite, but quite familiar with the MingW toolchain. I'm trying to understand what settings need to be made in a project to link to a dll or implib. Suppose I have created a dll and implib in one project in a given workspace. In another workspace and project I create a simple calling routine. How do I link to the dll in the first project? The calling program compiles successfully, but the linker reports that it can't find the dll. I have looked at the makefile and it appears to me as if there should be no problem locating the dll in the .DEBUG directory in the project where the dll was created.
I have tested the dll and caller using the MinGW toolchain using the Msys shell. The program runs as designed. So, it is clear to me that I'm not using the right IDE settings or perhaps the PATH environment variable is incorrect?
Any help with this novice question would be most appreciated. I've searched the forum and found some related materials, but haven't had success after reading them and trying to implement.
Regards,
Mark Allyn
I am very new to Codelite, but quite familiar with the MingW toolchain. I'm trying to understand what settings need to be made in a project to link to a dll or implib. Suppose I have created a dll and implib in one project in a given workspace. In another workspace and project I create a simple calling routine. How do I link to the dll in the first project? The calling program compiles successfully, but the linker reports that it can't find the dll. I have looked at the makefile and it appears to me as if there should be no problem locating the dll in the .DEBUG directory in the project where the dll was created.
I have tested the dll and caller using the MinGW toolchain using the Msys shell. The program runs as designed. So, it is clear to me that I'm not using the right IDE settings or perhaps the PATH environment variable is incorrect?
Any help with this novice question would be most appreciated. I've searched the forum and found some related materials, but haven't had success after reading them and trying to implement.
Regards,
Mark Allyn
- eranif
- CodeLite Plugin
- Posts: 6375
- Joined: Wed Feb 06, 2008 9:29 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: create and use a dll
Set the path to your DLL from:
Project Settings -> Linker -> Library Paths
And the name of the name of the DLL here (if you have more than one, separate them with semi-colon) :
Project Settings -> Linker -> Libraries
The name of the dll can be either a complete name (e.g. "libMyDll.dll") or partial name (e.g. "MyDll")
Eran
Project Settings -> Linker -> Library Paths
And the name of the name of the DLL here (if you have more than one, separate them with semi-colon) :
Project Settings -> Linker -> Libraries
The name of the dll can be either a complete name (e.g. "libMyDll.dll") or partial name (e.g. "MyDll")
Eran
Make sure you have read the HOW TO POST thread
-
- CodeLite Curious
- Posts: 6
- Joined: Thu Sep 29, 2011 3:51 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: create and use a dll
Eran-
Thanks for the rapid response. I did as you instructed (actually, I had tried this previously) and the build failed with the message: "No such file or directory".
I have also tried putting the dll in the same Debug folder along with the .o caller file and this did not work either. I have also tried using an import library instead of the DLL and setting the linker paths and library names as you suggested and this didn't work either.
I'd really like to solve this problem because I like the Codelite design very much and would like to use it instead of VC.
Thanks for your help.
Mark
Thanks for the rapid response. I did as you instructed (actually, I had tried this previously) and the build failed with the message: "No such file or directory".
I have also tried putting the dll in the same Debug folder along with the .o caller file and this did not work either. I have also tried using an import library instead of the DLL and setting the linker paths and library names as you suggested and this didn't work either.
I'd really like to solve this problem because I like the Codelite design very much and would like to use it instead of VC.
Thanks for your help.
Mark
- eranif
- CodeLite Plugin
- Posts: 6375
- Joined: Wed Feb 06, 2008 9:29 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: create and use a dll
Make sure you have read the HOW TO POST thread
-
- CodeLite Curious
- Posts: 6
- Joined: Thu Sep 29, 2011 3:51 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: create and use a dll
Hello Eran,
Spent the day looking for the bug. I think I may have identified it. I think I messed up on a #ifdef statement in the header file for the dll. If I still can't get it to run, I'll send you the log.
Thank you,
Mark
Spent the day looking for the bug. I think I may have identified it. I think I messed up on a #ifdef statement in the header file for the dll. If I still can't get it to run, I'll send you the log.
Thank you,
Mark
-
- CodeLite Curious
- Posts: 6
- Joined: Thu Sep 29, 2011 3:51 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: create and use a dll
Hi Eran,
Sorry, slow to return the log file. Here is a copy (I hope!):
I think the problem is probably due to incorrectly setting the path variable. My DLL is located in C:\MinGW\Mybin. I am linking to an import library named libhidll.a. If I am correctly reading the log file, the link to the imp lib is successful, but the dll itself is not on the search path. I've fooled around trying to set the path so that mingw\mybin is on it, but I don't think I'm doing it correctly.
Thanks,
Mark
Sorry, slow to return the log file. Here is a copy (I hope!):
Code: Select all
C:\WINDOWS\system32\cmd.exe /c ""mingw32-make.exe" -j 2 -f "hifoocaller_wsp.mk""
----------Building project:[ hifoocaller - Debug ]----------
mingw32-make[1]: Entering directory `c:/Documents and Settings/Administrator/My Documents/Codelite/hifoocaller/hifoocaller'
g++ -o ./Debug/hifoocaller.exe @"C:\Documents and Settings\Administrator\My Documents\Codelite\hifoocaller\hifoocaller\hifoocaller.txt" -L./Debug -lhidll
./Debug/foocall.o: In function `main':
C:/Documents and Settings/Administrator/My Documents/Codelite/hifoocaller/hifoocaller/foocall.cpp:7: undefined reference to `_imp__hifoo@0'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [Debug/hifoocaller.exe] Error 1
mingw32-make[1]: Leaving directory `c:/Documents and Settings/Administrator/My Documents/Codelite/hifoocaller/hifoocaller'
mingw32-make.exe: *** [All] Error 2
----------Build Ended----------
1 errors, 0 warnings
Thanks,
Mark
-
- CodeLite Curious
- Posts: 6
- Joined: Thu Sep 29, 2011 3:51 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: create and use a dll
Hi Eran,
OK, I finally got it. On the project settings page I entered the libpath as c:\mingw\mybin and on the libraries window I put mydll.dll. The program ran as intended.
However, I discovered something that does need explanation. Namely, if on the project settings -> library paths I enter the location of a .a import lib as for instance c:\blah\blah\ and in the project settings -> libraries window I enter hidll.a, the system seems unable to locate the dll in c:\mingw\mybin. Why is this so?
If I were to work directly off cmd.exe shell and do the link using the command: gcc -Lc:\blah\blah -o hifoocaller.exe hifoocaller.0 -lhidll, the system finds the hidll.dll in c:\mingw\mybin at runtime. Shouldn't it work the same way in Codelite?
Regards,
Mark
OK, I finally got it. On the project settings page I entered the libpath as c:\mingw\mybin and on the libraries window I put mydll.dll. The program ran as intended.
However, I discovered something that does need explanation. Namely, if on the project settings -> library paths I enter the location of a .a import lib as for instance c:\blah\blah\ and in the project settings -> libraries window I enter hidll.a, the system seems unable to locate the dll in c:\mingw\mybin. Why is this so?
If I were to work directly off cmd.exe shell and do the link using the command: gcc -Lc:\blah\blah -o hifoocaller.exe hifoocaller.0 -lhidll, the system finds the hidll.dll in c:\mingw\mybin at runtime. Shouldn't it work the same way in Codelite?
Regards,
Mark
- eranif
- CodeLite Plugin
- Posts: 6375
- Joined: Wed Feb 06, 2008 9:29 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: create and use a dll
It does work the same way. Just make sure that codelite's working directory is where it should beallynm wrote: Shouldn't it work the same way in Codelite?
If it does locate it from the shell - then it means that your DLL is placed in a directory which is set in your PATH environment variable, or you executable is located next to the DLL
The project settings -> linker is (like the name implies) the settings for the linker NOT for runtimeallynm wrote:if on the project settings -> library paths I enter the location of a .a import lib as for instance c:\blah\blah\ and in the project settings -> libraries window I enter hidll.a, the system seems unable to locate the dll in c:\mingw\mybin. Why is this so?
The Runtime locating DLLs by Windows is done by setting the PATH environment variable OR by placing the executable next to the DLL.
In any case, this has nothing to do with codelite, you should read some about how windows is locating its DLLs.
Eran
Make sure you have read the HOW TO POST thread
-
- CodeLite Curious
- Posts: 6
- Joined: Thu Sep 29, 2011 3:51 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: create and use a dll
Hi Eran,
Thanks for responding. I really appreciate your help.
The problem seems to be associated with the import library. The linker is not able to resolve the name of the imported function. I've DUMPBIN'ed the import library with /exports option and the library function name _hifoo appears in the output.
The import library is in the same Debug directory as the calling program's object file. The path to the library is set as: $(IntermediateDirectory). The library itself is libhidll.a and this is what is placed in the libraries window. The Makefile indicates that the make command has got the correct path and library specification.
As I say, if I set the library path to c:\MinGW\mybin and specifiy the library as hidll.dll, the program links and then executes properly.
Any further assistance you are willing to provide would be greatly appreciated. I really like Codelite and would like to use it as my personal standard.
Thanks for responding. I really appreciate your help.
The problem seems to be associated with the import library. The linker is not able to resolve the name of the imported function. I've DUMPBIN'ed the import library with /exports option and the library function name _hifoo appears in the output.
The import library is in the same Debug directory as the calling program's object file. The path to the library is set as: $(IntermediateDirectory). The library itself is libhidll.a and this is what is placed in the libraries window. The Makefile indicates that the make command has got the correct path and library specification.
As I say, if I set the library path to c:\MinGW\mybin and specifiy the library as hidll.dll, the program links and then executes properly.
Any further assistance you are willing to provide would be greatly appreciated. I really like Codelite and would like to use it as my personal standard.
- eranif
- CodeLite Plugin
- Posts: 6375
- Joined: Wed Feb 06, 2008 9:29 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: create and use a dll
I don't really use import libraries, I simply link against the DLL - so I can't help you there
Eran
Eran
Make sure you have read the HOW TO POST thread