0

I have created an application where it uses libssl which apparently uses libcrypto. I have kept these libraries at a user-defined location /path/to/xyz/lib/
---------------------------------------------------------------------------------------------------------------------------------

I have written a CMake for the application which links the libraries as follows:

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})

The CMake didnot give any error and created the Makefile which creates the executable.
---------------------------------------------------------------------------------------------------------------------------------

But When I run the executable. it throws the below error
./Foo: error while loading shared libraries: libcrypto.so.3: cannot open shared object file: No such file or directory

I have checked the dynamic linking of libssl.so as follows and found the libcrypto isn't linked...

[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)

I have checked the /path/to/xyz/lib/pkgconfig/libssl.pc file and found this suspicious for this error

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}

QUESTION
What does Requires.private: libcrypto do?
And how to solve this error?

--------------------------------------------------------------EDIT--------------------------------------------------------------
I have Done following edits in the cmake file

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)

I am getting segmentation fault by this change.

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)
RC0993
  • 898
  • 1
  • 13
  • 44
  • The problem is about RPATH settings. You may adjust these setting using CMake variable, see [RPATH handling](https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling). Or you may take any other answers to question https://stackoverflow.com/questions/8774593/cmake-link-to-external-library, which use **absolute paths** for libraries (e.g. [this one](https://stackoverflow.com/a/10550334/3440745)) - in that case CMake will automatically add RPATH which contains linked library. – Tsyvarev Jun 04 '19 at 14:19
  • I followed your suggestion and tried using `RPATH` but no luck. Please find the edited post – RC0993 Jun 05 '19 at 07:00
  • As you can see, the error message has been changed. Now it is "Segmentation fault (core dumped)". It is no longer an error from the `ldd`, it is the error from the **your program** which is crashed. – Tsyvarev Jun 05 '19 at 07:46

0 Answers0