Results 1 to 2 of 2

Thread: Help linking and using libs in simple project

  1. #1
    Join Date
    Sep 2014
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Help linking and using libs in simple project

    Hello,

    I am very new to QT and having trouble with a particular issue understanding how importing libs works in Qt. I have a very simple default Qt project for the MinGW compiler and I need to use a custom string class compiled in Visual Studio 2008. (I don't have access to the source, and there are other libs I need to work besides this one as well).

    #-------------------------------------------------
    #
    # Project created by QtCreator 2014-09-12T09:46:39
    #
    #-------------------------------------------------

    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = QtNVCDemo
    TEMPLATE = app


    SOURCES += main.cpp\
    mainwindow.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui

    win32: LIBS += -L$$PWD/../build-QtDemo-Desktop_Qt_5_3_MinGW_32bit-Debug/debug/ -lSString-4

    INCLUDEPATH += $$PWD/../build-QtDemo-Desktop_Qt_5_3_MinGW_32bit-Debug/debug
    DEPENDPATH += $$PWD/../build-QtDemo-Desktop_Qt_5_3_MinGW_32bit-Debug/debug

    win32:!win32-g++: PRE_TARGETDEPS += $$PWD/../build-QtDemo-Desktop_Qt_5_3_MinGW_32bit-Debug/debug/SString-4.lib
    else:win32-g++: PRE_TARGETDEPS += $$PWD/../build-QtDemo-Desktop_Qt_5_3_MinGW_32bit-Debug/debug/libSString-4.a
    I get this error
    :-1: error: No rule to make target 'C:/Users/bereall/QtDemo/../build-QtDemo-Desktop_Qt_5_3_MinGW_32bit-Debug/debug/libSString-4.a', needed by 'debug\QtDemo.exe'. Stop.
    The import lines were done trying to link a static lib using the wizard. What are .a libs and how do you create them? If I try changing the Sstring-4.a to the lib which I have it just says the same error? Trying to compile without the target dependencies lines works but then when I try to create a SString class or add the header to my project it doesn't recognize SString. Do I have to use libs created with the same compiler or can I import other libs?

    I just want to be able to import an external lib and be able to use its classes in my code. Haven't had any luck with reading old forum posts on this particular issue.

    Also if you're just trying to develop for Windows Desktop is MinGW the right compiler or should I be using msvc2010 opengl?

  2. #2
    Join Date
    Sep 2014
    Location
    Sydney, Australia
    Posts
    16
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help linking and using libs in simple project

    A '.a' file is an archive file. As I understand it, it tells the linker where to find your functions inside the dll.
    Your "SString-4.dll" should have come with a "SString-4.a" if it was for development use. If you don't have the .a file it's not the end of the world.

    -Download Dependency Walker.
    -Open your "SString-4.dll" with Dependency Walker.
    -On the middle-right side should be a list of all the functions contained in the dll.
    -Right click one of these functions and choose "Select All".
    -Right click again and choose "Copy function names".
    -Paste into Notepad and save as "SString-4.def" in the same directory as your dll.
    -The top line in the .def file should be "LIBRARY SString-4.dll". The next line should be "EXPORTS". Your list of functions will be below this.
    -After each function leave a space, then a "@" followed by the ordinal number of the function. You can get the ordinals by reading them off the list on Dependency Walker.
    Your .def file should now look something like this example here:

    Qt Code:
    1. LIBRARY K8055D.dll
    2. EXPORTS
    3. SetCounterDebounceTime @1
    4. ResetCounter @2
    5. ReadCounter @3
    6. ReadAllDigital @4
    7. ReadDigitalChannel @5
    8. SetAllDigital @6
    9. SetDigitalChannel @7
    10. ClearAllDigital @8
    11. ClearDigitalChannel @9
    12. WriteAllDigital @10
    13. SetAllAnalog @11
    14. SetAnalogChannel @12
    15. ClearAllAnalog @13
    16. ClearAnalogChannel @14
    17. OutputAllAnalog @15
    18. OutputAnalogChannel @16
    19. ReadAllAnalog @17
    20. ReadAnalogChannel @18
    21. CloseDevice @19
    22. OpenDevice @20
    To copy to clipboard, switch view to plain text mode 
    -Now open windows command line and type: PATH=%PATH%;C:\Qt\2010.05\mingw\bin (or whatever the path to 'dlltool' is on your build)
    -CD to the directory where your dll and .def files are located.
    -Then type: dlltool -v --dllname SString-4.dll --def SString-4.def --output-lib SString-4.a

    If all was successful you should see a list of stuff from dlltool and your .a file will be created.

    I've had to this before with dlls that didn't come with the required files so I understand your frustration -_-.
    Last edited by Nomad_Tech; 13th September 2014 at 13:59.
    "When the only tool you have is a hammer, every problem resembles a nail"

Similar Threads

  1. Replies: 2
    Last Post: 9th November 2012, 13:29
  2. Linking Qt-libs static
    By Simo in forum Qt Programming
    Replies: 1
    Last Post: 5th December 2011, 11:06
  3. Split project into shared libs - linking issue.
    By porterneon in forum Newbie
    Replies: 9
    Last Post: 30th May 2011, 14:15
  4. Linking 3rd party libs on Mac OS X
    By jonks in forum Qt Programming
    Replies: 2
    Last Post: 21st June 2010, 06:03
  5. Linking against different Libs
    By AlphaWolf in forum Qt Programming
    Replies: 3
    Last Post: 10th February 2009, 15: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.