无法将libssl链接到libcrypto

时间:2019-06-04 14:00:47

标签: ssl cmake linker pkg-config rpath

我创建了一个使用libssl的应用程序,其中显然使用了libcrypto。我已将这些库保存在用户定义的位置 /path/to/xyz/lib/
-------------------------------------------------- -------------------------------------------------- --------------------------------

我已经为应用程序编写了一个CMake,它按如下方式链接库:

set(GCC_LINK_FLAGS "-L/path/to/xyz/lib -lcurl -lpthread -lcrypto -lssl  //other libs")

add_executable(Foo ${APP_SOURCE_FILES})

target_link_libraries(Foo ${GCC_LINK_FLAGS})

CMake没有给出任何错误,并创建了创建文件,该文件创建了可执行文件。
-------------------------------------------------- -------------------------------------------------- --------------------------------

但是当我运行可执行文件时。会引发以下错误
./Foo: error while loading shared libraries: libcrypto.so.3: cannot open shared object file: No such file or directory

我检查了libssl.so的动态链接,如下所示,发现libcrypto没有链接...

[root@localhost build]# ldd /path/to/xyz/lib/libssl.so.3
        linux-vdso.so.1 =>  (0x00007fffa5fa7000)
        libcrypto.so.3 => not found
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f17ea772000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f17ea556000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f17ea193000)
        /lib64/ld-linux-x86-64.so.2 (0x0000563b0856f000)

我已经检查了/path/to/xyz/lib/pkgconfig/libssl.pc文件,并发现此错误可疑

prefix=/path/to/xyz/lib/
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: OpenSSL-libssl
Description: Secure Sockets Layer and cryptography libraries
Version: 3.0.0-dev
Requires.private: libcrypto
Libs: -L${libdir} -lssl
Cflags: -I${includedir}

问题
Requires.private: libcrypto是做什么的?
以及如何解决这个错误?

-------------------------------------------- - - - - - - - - - 编辑 - - - - - - - - - - - - - - - - -------------------------------
我对cmake文件进行了以下修改

set(CMAKE_SKIP_BUILD_RPATH  FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "/path/to/xyz/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

add_executable(SpeechToText ${APP_SOURCE_FILES})
target_link_libraries(Foo ${GCC_LINK_FLAGS})

install (TARGETS Foo RUNTIME DESTINATION /path/to/project/directory)

此更改使我遇到分段错误

Install the project...
-- Install configuration: ""
-- Installing: /path/to/project/directory/Foo
-- Set runtime path of "/path/to/project/directory/Foo" to "/path/to/xyz/lib"
[root@localhost build]# ../Foo 
Segmentation fault (core dumped)

0 个答案:

没有答案