使用cmake,make编译出的库可以找到它依赖的动态链接库,但是make install之后,就找不到了?

发布于 2022-09-12 03:00:00 字数 5175 浏览 47 评论 0

我的CMakeLists.txt如下:

project(libfsw)

cmake_minimum_required(VERSION 2.8)

enable_language(ASM)
set(FSW_VERSION 0.7.1)
set(FSW_CLFLAGS ssl crypt crypto)
set(CMAKE_CXX_STANDARD 11)
set(ENABLE_DEBUG OFF)
set(ENABLE_TRACE OFF)

if (DEFINED openssl_dir)
    include_directories(BEFORE ${openssl_dir}/include)
    link_directories(${openssl_dir}/lib)
else()
    message(FATAL_ERROR "you should set openssl_dir, eg:
    cmake . -Dopenssl_dir=/usr/local/openssl")
endif()

include(CheckFunctionExists)
check_function_exists(epoll_create HAVE_EPOLL)

option(ENABLE_DEBUGGER "Enable debug" ${ENABLE_DEBUG})
if (ENABLE_DEBUGGER)
    set(ENABLE_DEBUGGER 1)
    message ("-- Enable debug: yes")
else()
    set(ENABLE_DEBUGGER 0)
    message ("-- Enable debug: no")
endif()

option(ENABLE_TRACE "Enable trace" ${ENABLE_TRACE})
if (ENABLE_TRACE)
    set(ENABLE_TRACE 1)
    message ("-- Enable trace: yes")
else()
    set(ENABLE_TRACE 0)
    message ("-- Enable trace: no")
endif()

configure_file(${PROJECT_SOURCE_DIR}/config.h.in ${PROJECT_SOURCE_DIR}/include/config.h)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")

file(GLOB_RECURSE SRC_LIST FOLLOW_SYMLINKS src/*.c src/*.cc thirdparty/boost/asm/combined.S thirdparty/http/http_parser.c)
file(GLOB_RECURSE HEAD_FILES FOLLOW_SYMLINKS include/*.h thirdparty/http/*.h)

set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

include_directories(BEFORE ./include ./thirdparty/http)

#shared library
link_directories(${LIBRARY_OUTPUT_PATH})
add_library(libfsw SHARED ${SRC_LIST})
set_target_properties(libfsw PROPERTIES OUTPUT_NAME "fsw" VERSION ${FSW_VERSION})
target_link_libraries(libfsw ${FSW_CLFLAGS})

#install
install(CODE "MESSAGE(\"Are you run command using root user?\")")
install(TARGETS libfsw LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
install(FILES ${HEAD_FILES} DESTINATION include/fsw)

编译后,通过ldd可以找到所有依赖的动态链接库:

[root@159391e22367 fsw]# ldd lib/libfsw.so
    linux-vdso.so.1 =>  (0x00007ffd670e4000)
    libssl.so.1.1 => /usr/local/openssl/lib/libssl.so.1.1 (0x00007fa28894a000)
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fa288713000)
    libcrypto.so.1.1 => /usr/local/openssl/lib/libcrypto.so.1.1 (0x00007fa288229000)
    libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fa287f22000)
    libm.so.6 => /lib64/libm.so.6 (0x00007fa287c20000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fa287a0a000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fa28763c000)
    libz.so.1 => /lib64/libz.so.1 (0x00007fa287426000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007fa287222000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa287006000)
    libfreebl3.so => /lib64/libfreebl3.so (0x00007fa286e03000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fa288e41000)
[root@159391e22367 fsw]#

但是,执行make install之后,就找不到了:

[root@159391e22367 fsw]# make install
[100%] Built target libfsw
Install the project...
-- Install configuration: "Debug"
Are you run command using root user?
-- Up-to-date: /usr/local/lib/libfsw.so.0.7.1
-- Up-to-date: /usr/local/lib/libfsw.so
-- Up-to-date: /usr/local/include/fsw/help.h
-- Up-to-date: /usr/local/include/fsw/error.h
-- Up-to-date: /usr/local/include/fsw/coroutine_channel.h
-- Up-to-date: /usr/local/include/fsw/coroutine_http_server.h
-- Up-to-date: /usr/local/include/fsw/base64.h
-- Up-to-date: /usr/local/include/fsw/config.h
-- Up-to-date: /usr/local/include/fsw/event.h
-- Up-to-date: /usr/local/include/fsw/websocket_frame.h
-- Up-to-date: /usr/local/include/fsw/context.h
-- Up-to-date: /usr/local/include/fsw/coroutine.h
-- Up-to-date: /usr/local/include/fsw/timer.h
-- Up-to-date: /usr/local/include/fsw/buffer.h
-- Up-to-date: /usr/local/include/fsw/asm_context.h
-- Up-to-date: /usr/local/include/fsw/log.h
-- Up-to-date: /usr/local/include/fsw/coroutine_server.h
-- Up-to-date: /usr/local/include/fsw/process.h
-- Up-to-date: /usr/local/include/fsw/coroutine_socket.h
-- Up-to-date: /usr/local/include/fsw/coroutine_http.h
-- Up-to-date: /usr/local/include/fsw/socket.h
-- Up-to-date: /usr/local/include/fsw/unix_socket.h
-- Up-to-date: /usr/local/include/fsw/fsw.h
-- Up-to-date: /usr/local/include/fsw/http_parser.h

[root@159391e22367 fsw]# ldd /usr/local/lib/libfsw.so
    linux-vdso.so.1 =>  (0x00007ffc2d19b000)
    libssl.so.1.1 => not found
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fc1c34da000)
    libcrypto.so.1.1 => not found
    libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fc1c31d3000)
    libm.so.6 => /lib64/libm.so.6 (0x00007fc1c2ed1000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fc1c2cbb000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fc1c28ed000)
    libfreebl3.so => /lib64/libfreebl3.so (0x00007fc1c26ea000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fc1c3976000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007fc1c24e6000)
[root@159391e22367 fsw]#

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妄司 2022-09-19 03:00:01

我也遇到了相同的问题,请问你是咋解决的呢

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文