How can I add external library into a project built by Qt Creator RC1 (version 0.9.2)? For example, the win32 function EnumProcesses()
requires Psapi.lib
to be added in the project to build.
相关问题
- Sorting 3 numbers without branching [closed]
- QML: Cannot read property 'xxx' of undefin
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
相关文章
- ubuntu20.4中c#通过c++库调用python脚本
- Qt槽函数自动执行多遍
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
won't work because you're using white-spaces in Program Files. In this case you have to add quotes, so the result will look like this: LIBS += "C:\Program Files\OpenCV\lib". I recommend placing libraries in non white-space locations ;-)
I would like to add for the sake of completeness that you can also add just the LIBRARY PATH where it will look for a dependent library (which may not be directly referenced in your code but a library you use may need it).
For comparison, this would correspond to what LIBPATH environment does but its kind of obscure in Qt Creator and not well documented.
The way i came around this is following:
Essentially if you don't provide the actual library name, it adds the path to where it will search dependent libraries. The difference in syntax is small but this is very useful to supply just the PATH where to look for dependent libraries. It sometime is just a pain to supply each path individual library where you know they are all in certain folder and Qt Creator will pick them up.
If you want to deploy your application on machines of customers, rather than using your application only yourself, we find that the
LIBS+= -Lxxx -lyyy
method can lead to confusion if not problems.We develop applications for Linux, Mac and Windows using Qt. We ship complete, stand-alone applications. So all non-system libraries should be included in the deployment package. We want our customers to be able to run the application from the same USB stick for all OSs. For reasons of platform compatibility the USB stick must then be formatted as FAT32, which does not support (Linux) symlinks.
We found the
LIBS+= -Lxxx -lyyy
idiom too much of a black box:We do not exactly know what the filepath is of the (static or dynamic) library that has been found by the linker. This is inconvenient. Our Mac linker regularly found libs different from the ones we thought that should be used. This happened several times with OpenSSL libraries where the Mac linker found and used its own - older, incompatible - OpenSSL version rather than our requested version.
We cannot afford that the linker uses symlinks to libraries as this would break the deployment package.
We want to see from the name of the library whether we link a static or a dynamic library.
So for our particular case we use only absolute filepaths and check whether they exist. We remove all symlinks.
First we find out what operating system we are using and put this in the CONFIG variable. And, for instance for Linux 64bit, then:
All the dependencies can be copied into deployment package as we know their filepaths.
And to add multiple library files you can write as below:
in .pro:
LIBS += Ole32.lib OleAut32.lib Psapi.lib advapi32.lib
in .h/.cpp:
#pragma comment(lib,"user32.lib")
Are you using
qmake
projects? If so, you can add an external library using theLIBS
variable. E.g: