我正在尝试为c++项目配置cmake并链接我的库。由于某些原因,我不能让cmake在./lib//文件夹中找到我的库。根据文档,库搜索路径应该是/lib/。
我尝试过使用空前缀和"./“,但这两种情况都没有找到我的库。
如果我在find_library()中给出提示,那么它就被找到了,但是为什么没有提示就找不到它呢?
这是我的CMakeList.txt:
cmake_minimum_required(VERSION 3.0.0)
project(UntitledProject VERSION 0.1.0)
include(CTest)
enable_testing()
message("ARCH: " ${CMAKE_LIBRARY_ARCHITECTURE})
message("PREFIX: " ${CMAKE_PREFIX_PATH})
message("LIB: " ${CMAKE_LIBRARY_PATH})
find_library(LIBMYLIB mylibrary)
message("MYLIB: " ${LIBMYLIB})
add_executable(UntitledProject main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)共享库确实存在:
$ file lib/x86_64-linux-gnu/libmylibrary.so
lib/x86_64-linux-gnu/libmylibrary.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=e34ba5ae24d6a09bfb847a46cd669ea7e101e8a4, stripped这是cmake configure的输出:
[cmake] The C compiler identification is GNU 7.5.0
[cmake] The CXX compiler identification is GNU 7.5.0
[cmake] Check for working C compiler: /usr/bin/x86_64-linux-gnu-gcc-7
[cmake] Check for working C compiler: /usr/bin/x86_64-linux-gnu-gcc-7 -- works
[cmake] Detecting C compiler ABI info
[cmake] Detecting C compiler ABI info - done
[cmake] Detecting C compile features
[cmake] Detecting C compile features - done
[cmake] Check for working CXX compiler: /usr/bin/x86_64-linux-gnu-g++-7
[cmake] Check for working CXX compiler: /usr/bin/x86_64-linux-gnu-g++-7 -- works
[cmake] Detecting CXX compiler ABI info
[cmake] Detecting CXX compiler ABI info - done
[cmake] Detecting CXX compile features
[cmake] Detecting CXX compile features - done
[cmake] ARCH: x86_64-linux-gnu
[cmake] PREFIX:
[cmake] LIB:
[cmake] MYLIB: LIBMYLIB-NOTFOUND
[cmake] Configuring done
[cmake] Generating done我遗漏了什么?
发布于 2020-11-26 10:09:11
也许您可以尝试使用命令行中的绝对路径而不是./来设置CMAKE_PREFIX_PATH
发布于 2020-11-26 23:08:00
如果我在find_library()中给出提示,那么它就被找到了,但是为什么没有提示就找不到它呢?
因为在默认情况下,find_library在系统路径中进行搜索,在Linux中,该路径通常是/usr/lib或/usr/local/lib。
要修复此问题,可以创建从lib/x86_64-linux-gnu/到/usr/local/lib的符号链接
sudo ln -s lib/x86_64-linux-gnu/libmylibrary.so /usr/local/lib/libmylibrary.sohttps://stackoverflow.com/questions/65014274
复制相似问题