Adding external library into Qt Creator project

后端 未结 8 1765
广开言路
广开言路 2020-11-22 09:39

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<

8条回答
  •  不思量自难忘°
    2020-11-22 10:19

    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:

    1. 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.

    2. We cannot afford that the linker uses symlinks to libraries as this would break the deployment package.

    3. 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:

    linux64 {
        LIBSSL= $$OPENSSLPATH/linux64/lib/libssl.a
        !exists($$LIBSSL): error ("Not existing $$LIBSSL")
        LIBS+= $$LIBSSL
        LIBCRYPTO= $$OPENSSLPATH/linux64/lib/libcrypto.a
        !exists($$LIBCRYPTO): error ("Not existing $$LIBCRYPTO")
        LIBS+= $$LIBCRYPTO
    }
    

    All the dependencies can be copied into deployment package as we know their filepaths.

提交回复
热议问题