简体   繁体   中英

how to add shared library to QtCreator

I've got a project which involves the use of two libraries. I've tried to add the libraries to be included into my .pro file, but when i compile i receive a "cannot find -lmylib1".

INCLUDEPATH += ./lib/mylib1 \
               ./lib/mylib2

LIBS += -L"$$_PRO_FILE_PWD_/lib/mylib1" -lmylib1 \
        -L"$$_PRO_FILE_PWD_/lib/mylib2" -lmylib2

The directory structure is as below.

Myproject.pro
lib (directory)
     mylib1 (directory)
         mylib1.so
     mylib2 (directory)
         mylib2.so

To complete @dave comment, it is not only that Qt Creator only searches for files with the names "lib*.so". It is the default behavior for linkers on UNIX-like systems.

Quoting the documentation for the ld linker:

-larchive

[...] ld will search its path-list for occurrences of libarchive.a for every archive specified. On systems which support shared libraries, ld may also search for libraries with extensions other than .a. Specifically, on ELF and SunOS systems, ld will search a directory for a library with an extension of .so before searching for one with an extension of .a. By convention, a .so extension indicates a shared library. [...] This type of archive searching is standard for Unix linkers.

So if your library does not match the lib*.a or lib*.so patterns, it is expected that both Qt Creator and the linker do not find it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM