How to link an existing .exe to a DLL?
I have created a project, executable called, app.exe.
Then another project, executable called, proj.dll, together with proj.lib and few other header files.
How do I link my first project, app.exe to the proj.dll?
What are the step by step details and configuration settings I am required to do, so that both the projects
can be linked successfully?
I'm doing programming for Windows platform, and using Qt 4.6.2 and Qt Creator 1.3.1.
Please help.
Re: How to link an existing .exe to a DLL?
Do you wish to link them at run time or at compile time?
Re: How to link an existing .exe to a DLL?
I want to link them at run time.Please advise.Thank you.
Re: How to link an existing .exe to a DLL?
specify all the .lib files as library inputs(also specify the library files path) and place all the required/corresponding dlls folder path in env PATH variable such that exe can link with the dlls during runtime.
Re: How to link an existing .exe to a DLL?
Hi, Thank you for the reply.
Could you please give me examples for :
"specify all the .lib files as library inputs(also specify the library files path)"
and "place all the required/corresponding dlls folder path in env PATH variable"
?
Thank you.
Re: How to link an existing .exe to a DLL?
Hi, I forgot to mention that the app.exe was created/built using QT environment and proj.dll, proj.lib and the header files were created/built using VS2005 environment...
Re: How to link an existing .exe to a DLL?
Quote:
Originally Posted by
babygal
Hi, I forgot to mention that the app.exe was created/built using QT environment and proj.dll, proj.lib and the header files were created/built using VS2005 environment...
Okay, so your app.exe was linked at compile time with corresponding proj.lib, yes?
If yes, then add path to the directory containing your proj.dll to the PATH environment variable or simply copy proj.dll to the same directory where app.exe is.
EDIT:
If you want to load a library at runtime without compile time linking, then use QLibrary.
But I understand that you want to link it in compile time with .lib and run with .dll, which is simple.
But can you explain what does it mean "Qt environment"? Qt does not contain any C++ compiler, so if you have compiled it on the same PC as proj.dll then you probably used your VS compiler, or you have Qt SDK with MinGW installed so it uses MinGW for compiling, so then you need proj.a instead of proj.lib.
Can you show us what have you tried?
Re: How to link an existing .exe to a DLL?
Hi , below are my answers,
1>>>"Okay, so your app.exe was linked at compile time with corresponding proj.lib, yes?"
- I think app.exe is not linked at compile time with corresponding proj.lib.by the way, how can I confirm this?
2>>But can you explain what does it mean "Qt environment"? Qt does not contain any C++ compiler, so if you have compiled it on the same PC as proj.dll then you probably used your VS compiler, or you have Qt SDK with MinGW installed so it uses MinGW for compiling, so then you need proj.a instead of proj.lib.
QT environment - I was referring to QT creator.
No, the app.exe and proj.dll are compiled on different PCs.The proj.dll is built using VS compiler,whereas,
the app.exe is built using MinGW.
Q: Do I need a proj.a instead of proj.lib?I don't understand.
================================================== =======================
Here is an extract of my app.pro file: ( .\lib contains ((CAT_DLL.lib) == (proj.lib)) and app.exe and ((CAT_DLL.dll)==(proj.dll)) are in same folder which is the \Debug folder.
================================================== =======================
TEMPLATE = app
LIBS += -L/./lib -lCAT_DLL
CONFIG += dll CAT_DLL.dll
INCLUDEPATH += ./lib
INCLUDEPATH += ./Debug
INCLUDEPATH += ./Temp (Temp folder contains few header files which is supposed to be for the proj.dll )
HEADERS += ...all header files
FORMS += mainwindow.ui
SOURCES += ...all source files
RESOURCES += cardiacprocessingtoolkit.qrc
================================================== ==================
>>Compile output:
c:/qt/2010.02.1/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -lCAT_DLL
collect2: ld returned 1 exit status
mingw32-make[1]: Leaving directory `C:/Documents and Settings/muniandyu/My Documents/Visual Studio 2005/Projects/Work/Cardiac_CAT DLL_WIP/Cardiac'
mingw32-make[1]: *** [debug\Cardiac.exe] Error 1
mingw32-make: Leaving directory `C:/Documents and Settings/muniandyu/My Documents/Visual Studio 2005/Projects/Work/Cardiac_CAT DLL_WIP/Cardiac'
mingw32-make: *** [debug] Error 2
Exited with code 2.
Error while building project Cardiac
When executing build step 'Make'
Re: How to link an existing .exe to a DLL?
okay, so:
1. LIBS qmake variable describes with which libraries your target (in your case app.exe) should be linked. But this means (on Windows) that you need two files describing your library:
- proj.lib, proj.dll - if you are compiling with VS. Then .lib is the file to link with during compilation and .dll is a file used during runtime and loaded automatically if you linked with .lib while compiling
- proj.a (or libproj.a - not sure about this), proj.dll - when using MinGW - similar to VS: .a - for linking at compile time, .dll - for loading at runtime.
2. To link at compile time you have to add to your .pro:
Code:
LIBS += -Lpath/to/library -lnameoflibrary
3. remove CONFIG += dll CAT_DLL.dll as your target is not a dll but executable file!
4. your compiler said that it cannot find your library, check path and check if there is required CAT_DLL.a (or libCAT_DLL.a) file.
Re: How to link an existing .exe to a DLL?
Hi, Thank you so much for the reply.
Just to confirm,in my case, I need proj.lib or proj.a ?
Thank you.
Re: How to link an existing .exe to a DLL?
Re: How to link an existing .exe to a DLL?
Hi,
Could you explain further?
My app.exe is compiled using MinGW and proj.dll is compiled using VS.
and I wish to link my app.exe with the proj.dll.(however, i wish to compile and link both using MinGW)
So am I doing it correctly now,or I need a proj.a to link with my app.exe?(by the way can VS output *.a file?)
bit confused *-)
Re: How to link an existing .exe to a DLL?
If you compile your app.exe with MinGW then all libraries you link to has to be .a
So you have to convert your proj.lib to proj.a (or as I said it can be libproj.a - not sure about it).
Search the net or forum to find how to do it. It was mentioned some days ago in some post here on QtCentre, AFAIR the tools are 'dlltool' and reimp or something like this.
Re: How to link an existing .exe to a DLL?
It is difficult to link MVSC DLL to GCC executable by using static stub.
The easiest way would be to use QLibrary in this instance, then you don't need .a or .lib files, just the DLL.
Re: How to link an existing .exe to a DLL?
So another solution might be to use VisualStudio Express Edition and compile Qt with it :] (I don't remember if there is WindowsSDK or rather PlatformSDK needed for this)
Re: How to link an existing .exe to a DLL?
That'll work, just remember that the Express editions don't support the Qt addin.
Re: How to link an existing .exe to a DLL?
Quote:
Originally Posted by
faldżip
So another solution might be to use VisualStudio Express Edition and compile Qt with it :] (I don't remember if there is WindowsSDK or rather PlatformSDK needed for this)
Hi , I don't know how to do this?Could you explain.
Re: How to link an existing .exe to a DLL?
Quote:
Originally Posted by
fatjuicymole
That'll work, just remember that the Express editions don't support the Qt addin.
Hi, What is Qt addin and what is it's purpose?
Re: How to link an existing .exe to a DLL?
Re: How to link an existing .exe to a DLL?
Hi,, Which is the easiest method and how to do it?