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

codinghuang
  • 143

我的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]#
评论
阅读 1k
1 个回答
Einstok
  • 1
新手上路,请多包涵

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

撰写回答

登录后参与交流、获取后续更新提醒

宣传栏