Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: How to link an existing .exe to a DLL?

  1. #1
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Question 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.
    Last edited by babygal; 20th April 2010 at 08:47.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to link an existing .exe to a DLL?

    Do you wish to link them at run time or at compile time?

  3. The following user says thank you to squidge for this useful post:

    babygal (27th April 2010)

  4. #3
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to link an existing .exe to a DLL?

    I want to link them at run time.Please advise.Thank you.

  5. #4
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default 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.
    Last edited by nikhilqt; 21st April 2010 at 07:35.

  6. The following user says thank you to nikhilqt for this useful post:

    babygal (27th April 2010)

  7. #5
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Question 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.

  8. #6
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Question 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...

  9. #7
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to link an existing .exe to a DLL?

    Quote Originally Posted by babygal View Post
    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?
    Last edited by faldzip; 21st April 2010 at 10:22. Reason: updated contents

  10. The following user says thank you to faldzip for this useful post:

    babygal (27th April 2010)

  11. #8
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Question 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'
    Last edited by babygal; 21st April 2010 at 11:12.

  12. #9
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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:
    Qt Code:
    1. LIBS += -Lpath/to/library -lnameoflibrary
    To copy to clipboard, switch view to plain text mode 

    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.

  13. The following user says thank you to faldzip for this useful post:

    babygal (27th April 2010)

  14. #10
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Question 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.

  15. #11
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to link an existing .exe to a DLL?

    GCC uses .a
    VC uses .lib

  16. The following user says thank you to squidge for this useful post:

    babygal (27th April 2010)

  17. #12
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Question 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 *-)
    Last edited by babygal; 22nd April 2010 at 09:20.

  18. #13
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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.

  19. The following user says thank you to faldzip for this useful post:

    babygal (27th April 2010)

  20. #14
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  21. The following user says thank you to squidge for this useful post:

    babygal (27th April 2010)

  22. #15
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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)

  23. The following user says thank you to faldzip for this useful post:

    babygal (27th April 2010)

  24. #16
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  25. The following user says thank you to squidge for this useful post:

    babygal (27th April 2010)

  26. #17
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to link an existing .exe to a DLL?

    Quote Originally Posted by faldżip View Post
    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.

  27. #18
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to link an existing .exe to a DLL?

    Quote Originally Posted by fatjuicymole View Post
    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?

  28. #19
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

  29. The following user says thank you to squidge for this useful post:

    babygal (27th April 2010)

  30. #20
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to link an existing .exe to a DLL?

    Hi,, Which is the easiest method and how to do it?

Similar Threads

  1. Completer with existing ui form
    By vladozar in forum Qt Programming
    Replies: 1
    Last Post: 12th December 2009, 16:35
  2. How to write qt4 gui up to the existing console
    By binaural in forum Qt Programming
    Replies: 4
    Last Post: 16th June 2009, 14:44
  3. Add existing project
    By danesh in forum Qt Programming
    Replies: 12
    Last Post: 23rd April 2009, 20:47
  4. replace existing process with the new one
    By memus in forum Qt Programming
    Replies: 1
    Last Post: 14th August 2008, 17:40
  5. Installing Qt 4 with existing Qt3
    By Honestmath in forum Installation and Deployment
    Replies: 2
    Last Post: 27th March 2006, 22:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.