0

There are two versions of openssl in my virtual machine, one is in /usr/include and /usr/lib, and the other is the version I modified myself, which is installed in /opt/openssl and modified by myself.I want to link to my customized openssl project located in /opt/openssl via cmake. The code is run on Ubuntu 22.04.

The modified version has neither OpenSSLConfig.cmake nor openssl-config.cmake, which causes an error when I executed find_package (OpenSSL REQUIRED PATHS /opt/openssl). I also tried set(OPENSSL_INCLUDE_DIR "/opt/openssl/include") set(OPENSSL_LIBRARY_DIR "/opt/openssl/lib64") and at the end target_link_libraries(tutorial-01-wget PRIVATE /opt/openssl/lib64/libssl.so /opt/openssl/lib64/libcrypto.so ${WORKFLOW_LIB}) But the final detected version and the packet capture analysis all show that the link should be the version in my /usr/include, which makes me very confused how to solve it.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • "show that the link should be the version in my `/usr/include`" - Probably, `/usr/include` is added as include directory in some other part of your project. When search a header, a compiler iterate over include directories in order, and the first finding wins. You will have a hard time attempting to force CMake, compiler and runtime loader to ignore a library located in the **standard directory** `/usr/lib`. – Tsyvarev Jun 06 '23 at 09:45
  • BTW, it is possible that `/usr/include` is the **default include directory** for your compiler. [That question](https://stackoverflow.com/questions/4980819/what-are-the-gcc-default-include-directories) describes a way how to check that assumption. – Tsyvarev Jun 06 '23 at 09:48
  • According to the docs for [the `FindOpenSSL` module](https://cmake.org/cmake/help/latest/module/FindOpenSSL.html#hints) setting `OPENSSL_ROOT_DIR` may be required. Note that using `PATHS` only provides hints for searching for package configuration files in `CONFIG` mode, i.e. when cmake is looking for `OpenSSLConfig.cmake` or `openssl-config.cmake`. – fabian Jun 06 '23 at 16:37
  • Unfortunately, I found that sudo apt remove openssl could not delete openssl in /usr/include and /usr/lib. I tried to reinstall /opt/openssl in /usr/local. Will this help? But at present I still can't find_package, and I must admit that I found that the code in the project is indeed #include , does this mean that I have to delete the original openssl forcibly, and then Install my current project in /opt/openssl in /usr/include and /usr/lib – user22027287 Jun 07 '23 at 07:07

1 Answers1

0

finally I achieve it by:

set(OPENSSL_INCLUDE_DIR "/opt/openssl/include")
set(OPENSSL_LIBRARY_DIR "/opt/openssl/lib64")
find_package(OpenSSL REQUIRED )
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 26 '23 at 00:31