Results 1 to 8 of 8

Thread: Linking a .a and .dll library to Qt project

  1. #1
    Join Date
    Sep 2012
    Posts
    31
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Linking a .a and .dll library to Qt project

    Hi, I am currently developing a qt sub directory project. This is the structure:

    Root Project:
    Root.pro
    Subdir Project:
    Subdirapp.pro - TEMPLATE = app
    Subdirlib1.pro - TEMPLATE = lib
    Subdirlib2.pro - TEMPLATE = lib
    Subdirlib3.pro - TEMPLATE = lib
    Subdirlib4.pro - TEMPLATE = lib


    First, I would like to ask how can I create a shared library for the subdirectory projects(Subdirlib1.pro,Subdirlib2.pro,Subdirlib3. pro and Subdirlib4.pro).
    Second, I would like to ask how can I link those subdir projects using this shared library allowing me to use UI and functions of every

    Upon building the projects. ".a" and ".dll" were generated.
    I am currently working on MINGW build configuration.

    I really need your help guys! Please.
    Thanks in advance

    -ehnuh-

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Linking a .a and .dll library to Qt project

    If you have DLL generated for each library sub project then you already have shared libraries.

    In the app project pro file you add the libraries/library paths you wish to link against to the LIBS variable and, if necessary, add an include search directory to INCLUDEPATH.

  3. #3
    Join Date
    Sep 2012
    Posts
    31
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Linking a .a and .dll library to Qt project

    Hi sir, currently I have tried this method:


    ..I am currently using mingw compiler, so the library file format generated is a '.a' and '.dll' format.

    I added the library using 'add internal library'. This generated the code in my .pro file.

    unix:!symbian|win32: LIBS += -L$$OUT_PWD/../../../BiTCommon/Template/Project/ -lTemplate

    INCLUDEPATH += $$PWD/../../../BiTCommon/Template/Include
    DEPENDPATH += $$PWD/../../../BiTCommon/Template/Include


    ..upon building the project, it gives me this error.
    'cannot find -lTemplate'


    ..Next I tried to change the -lTemplate to -aTemplate since the library generated was in a '.a' format. Upon building there were no errors but when I instantiated the class it gave me this error.


    error: undefined reference to `_imp___ZN19CTemplateMainWindowC1EP7QWidget'



    ..any inputs would really be helpful. To cut the long story short, I was previously compiling in msvc and it generated .lib files and I just link it to my project. Now that it is in mingw, it generates a different file format.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Linking a .a and .dll library to Qt project

    You are telling Qt that there is a library called "libTemplate.a" in a folder "$$OUT_PWD/../../../BiTCommon/Template/Project/" (wherever that resolves to) or elsewhere on the standard path. I guess it is not there.

  5. #5
    Join Date
    Sep 2012
    Posts
    31
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Linking a .a and .dll library to Qt project

    Hi sir thanks for the reply! When 'add an internal library' option is chosen in Qt, it detects the .pro files in the subdirs project. When 'add an external library' is chosen, it only detects .lib files. It does not detect the .a files.


    Added after 18 minutes:


    Hi sir! Thanks for the input! Just realized that I was calling the library from the wrong path. I had to manually edit the path to the correct library path. I instantiated the class and the UI showed! Thanks!
    Last edited by ehnuh; 11th October 2012 at 10:01.

  6. #6
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Linking a .a and .dll library to Qt project

    Hey,

    i need to link qwt library to my program:

    i changed the pro file the following way:

    CONFIG += qwt

    #-the port com library :
    INCLUDEPATH += C:\Qt\qextserialport-1.2win-alpha\
    LIBS += C:\Qt\qextserialport-1.2win-alpha\build\libqextserialportd.a

    #-the graphic library :
    INCLUDEPATH += C:\QtSDK\qwt-6.0.0\src\
    LIBS += C:\QtSDK\qwt-6.0.0\lib\libqwtd.a

    but it says libqwtd.a is not a directory
    and libqextserialportd.a is not a directory.

    The folder also has .dll files but the same happens...

    Pls suggest what should i do???

  7. #7
    Join Date
    Apr 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Linking a .a and .dll library to Qt project

    Has anyone answered this anywhere?
    I have a similar issue on windows. I get both mylib.dll and libmylib.a created. Nothing you do will allow the classes/methods be used in another project.
    I have this in my exe pro file:
    INCLUDEPATH += /cpp/qt/mylib
    LIBS += -L/cpp/qt/mylib/debug -lmylib

    This DOES NOT WORK...get undefined references to all the used methods.
    This DOES WORK under linux without issue.

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Linking a .a and .dll library to Qt project

    Firstly, where do you suppose the path "/cpp/qt/mylib/" is on a Windows machine? Without the drive specified this may not be where you think it is.

    Assuming the library file itself is actually found by the linker: if your dynamic library does not export the symbols you wish to use then they will not be visible. GCC on LInux exports by default, on Windows it does not. See Using Symbols from Shared Libraries in the friendly manual.

    Next time you might try providing more information about the actual problem, like the relevant output from the linker, rather than just shouting that it does not work.

Similar Threads

  1. Linking DLL to Project
    By lynchkp in forum Newbie
    Replies: 4
    Last Post: 29th January 2012, 05:36
  2. Problem linking against library
    By PowerPlate in forum Qt Programming
    Replies: 3
    Last Post: 15th October 2011, 02:45
  3. linking .so library in Qt on Mac Platform.
    By syclopse in forum Qt Programming
    Replies: 0
    Last Post: 18th August 2011, 10:50
  4. Help needed linking to library
    By StephenR in forum Qt Programming
    Replies: 4
    Last Post: 3rd July 2009, 08:50
  5. linking qt3 to a library
    By thebra in forum Newbie
    Replies: 10
    Last Post: 11th November 2006, 01:25

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.