Adding External Library into Qt Creator Project

Adding external library into Qt Creator project

The proper way to do this is like this:

LIBS += -L/path/to -lpsapi

This way it will work on all platforms supported by Qt. The idea is that you have to separate the directory from the library name (without the extension and without any 'lib' prefix). Of course, if you are including a Windows specific lib, this really doesn't matter.

In case you want to store your lib files in the project directory, you can reference them with the $$_PRO_FILE_PWD_ variable, e.g.:

LIBS += -L"$$_PRO_FILE_PWD_/3rdparty/libs/" -lpsapi

How add shared-library to my library project in QT

Just go to your respective Qt .pro file in Qt Creator IDE itself, and right click on empty area and choose "Add Library", Select external Library and click next, now click on browse in front of include path text box and choose the .lib file you want to include and select the platforms you want to target and now click next and finish the process. To add .h file, first copy the .h file in your project folder, and right click on the header under solution explorer, and click on add existinf file, now select your .h file and add it.

Include path for adding an external library in Qt Creator?

See the documentation for include path, and libs.

Also note that you need to link with the files ending with 'd' in the debug build and the others in release (also if you use x86 and x64 builds, you should use the correct libraries), here is a sample from a test .pro (i only use x86 and vc10):

INCLUDEPATH += D:\\ProgrammingTools\\opencv\\build\\include

CONFIG( debug, debug|release ) {
LIBS += -LD:\\ProgrammingTools\\opencv\\build\\x86\\vc10\\lib\
-lopencv_core246d\
-lopencv_highgui246d\
-lopencv_imgproc246d\
-lopencv_features2d246d\
}
else {
LIBS += -LD:\\ProgrammingTools\\opencv\\build\\x86\\vc10\\lib\
-lopencv_core246\
-lopencv_highgui246\
-lopencv_imgproc246\
-lopencv_features2d246\
}

Notice that there is -L__NO_SPACE_PATHTOLIB and -l_NOSPACE__libname, you don't need to add all the lib files, you only add the ones that you use functions from, and also the samples include files like this:

#include <opencv2/opencv.hpp>

so the include-path ends in a folder that contains two folders (not the actual header files)

How to add an external .a library in Qt Creator project via GUI?

As far as I know it is impossible now. The only way is to edit .pro file and add such lines:

win32 {
#/* If you compile with QtCreator/gcc: */
win32-g++:LIBS += -L"$$_PRO_FILE_PWD_/libs/"
win32-g++:LIBS += -lyaml-cpp

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


macx {
LIBS += -L"$$_PRO_FILE_PWD_/libs/"
LIBS += -lyaml-cpp-mac
}


Related Topics



Leave a reply



Submit