PDA

View Full Version : How to link an existing .exe to a DLL?



babygal
20th April 2010, 08:35
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.

squidge
20th April 2010, 08:57
Do you wish to link them at run time or at compile time?

babygal
20th April 2010, 09:26
I want to link them at run time.Please advise.Thank you.

nikhilqt
21st April 2010, 07:27
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.

babygal
21st April 2010, 07:50
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.

babygal
21st April 2010, 08:34
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...

faldzip
21st April 2010, 10:16
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?

babygal
21st April 2010, 11:07
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'

faldzip
21st April 2010, 12:15
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:


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.

babygal
22nd April 2010, 04:42
Hi, Thank you so much for the reply.
Just to confirm,in my case, I need proj.lib or proj.a ?

Thank you.

squidge
22nd April 2010, 08:57
GCC uses .a
VC uses .lib

babygal
22nd April 2010, 09:16
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 *-)

faldzip
22nd April 2010, 11:02
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.

squidge
22nd April 2010, 14:10
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.

faldzip
22nd April 2010, 15:04
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)

squidge
22nd April 2010, 16:10
That'll work, just remember that the Express editions don't support the Qt addin.

babygal
26th April 2010, 04:20
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.

babygal
26th April 2010, 04:31
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?

squidge
26th April 2010, 08:57
http://qt.nokia.com/developer/faqs/what-is-the-visual-studio-add-in

http://doc.trolltech.com/4.6/deployment-windows.html

babygal
26th April 2010, 11:22
Hi,, Which is the easiest method and how to do it?

squidge
26th April 2010, 14:44
Depends on the DLL complexity and your skill level. Read this entire thread, choose the one that you understand the most and choose that.

faldzip
26th April 2010, 15:23
That'll work, just remember that the Express editions don't support the Qt addin.
But you can have MSVC and use it in Qt Creator - that is the way I choose :] and you don't need any Qt Add-in
Nice developing with Qt connected with nice and completly Windows way to produce Windows application. I don't like MinGW as it looks like forcing applications compiled with Unix compiler to run on Windows - 1st thought: rather not comfortable and not efficient.

squidge
26th April 2010, 20:01
Which is why I use Visual Studio 2008. QtCreator is nice, but VS2008 with the plugins you are used to is much better. My full time job is software engineer, I use VS at work and work pays for the home VS license too, so it makes sense to me.

But of course the situation is different for each person. I'm not sure on the deployment licensing of VS express edition, but using the VS EE under QtCreator is a good choice for non-commercial work.

babygal
27th April 2010, 09:08
But you can have MSVC and use it in Qt Creator - that is the way I choose :] and you don't need any Qt Add-in
Nice developing with Qt connected with nice and completly Windows way to produce Windows application. I don't like MinGW as it looks like forcing applications compiled with Unix compiler to run on Windows - 1st thought: rather not comfortable and not efficient.

1. How to "have MVSC and use it in Qt Creator"?If I do it this way, compiling is done using VC or GCC?