Results 1 to 20 of 24

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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 07: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 06: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 09: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 10: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)

Similar Threads

  1. Completer with existing ui form
    By vladozar in forum Qt Programming
    Replies: 1
    Last Post: 12th December 2009, 15: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, 13:44
  3. Add existing project
    By danesh in forum Qt Programming
    Replies: 12
    Last Post: 23rd April 2009, 19:47
  4. replace existing process with the new one
    By memus in forum Qt Programming
    Replies: 1
    Last Post: 14th August 2008, 16:40
  5. Installing Qt 4 with existing Qt3
    By Honestmath in forum Installation and Deployment
    Replies: 2
    Last Post: 27th March 2006, 21: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.