Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using External Lib/DLLs in Qt Creator?

Tags:

c++

qt

I decided after a bunch of headaches all morning, that using Qt Creator for my first Qt project would probably be better than MSVC (had too many issues compiling).

I am wondering though how I can add the .dlls and .libs I need for my external tools through Qt Creator. I found this post Adding external library into Qt Creator project which makes sense.

I need a little more info though such as...Do I link dlls or libs first, what is the syntax to add dlls to the build step in qmake (i assume its close to win32:LIBS += path/to/Psapi.lib)

Thanks!

like image 884
George Geankins Avatar asked Oct 04 '10 19:10

George Geankins


1 Answers

Compiling external libraries with QtCreator/gcc

If you own the source code of your libraries this is the .pro file to make an external library (.dll and .a) or Framework (on Mac OS X) from them:

TEMPLATE = lib

INCLUDEPATH = <your-include-paths>
HEADERS += <your-headers>
SOURCES += <your-sources>
TARGET = MyLib  /* The name of your libary */

/* Win32: To generate a MyLib.dll and libMyLib.a (gcc) or MyLib.lib (MSVC) file */
win32 {
    CONFIG += dll
}

/* Just in case you need to generate Mac Frameworks: */
macx {
    CONFIG += shared lib_bundle
    FRAMEWORK_HEADERS.version = Versions
    FRAMEWORK_HEADERS.files += <your library headers>
    /* Example:
    FRAMEWORK_HEADERS.files += /path/to/your/lib/MyLib.h
    */
    FRAMEWORK_HEADERS.path = Headers
    QMAKE_BUNDLE_DATA = FRAMEWORK_HEADERS
    VERSION = 0.5.0   // a framework version you can define
}

Adding external libraries to your QtCreator/gcc project

/* your project settings */

/* If you compile on windows */
win32 {
    /* If you compile with QtCreator/gcc: */
    win32-g++:LIBS += /path/to/your/libMyLib.a

    /* IF you compile with MSVC: */
    win32-msvc:LIBS += /path/to/your/libMyLib.lib
}

/* If compile on Mac and want to link against a framework */
macx {
    LIBS+= -framework MyLib
    QMAKE_FLAGS += -F/path/to/MyLib
}

Note that to use external libraries with gcc you need the libMyLib.a file that contains the linking information. The libMyLib.lib are generated by MS Visual Studio and can't be processed by gcc afaik!

like image 121
WolfgangP Avatar answered Sep 26 '22 23:09

WolfgangP