Search code examples
cmakeopenssl

CMake Error: fatal error: openssl/core_names.h: No such file or directory


I have cmake project which uses openssl for TLS, I have installed openssl into my system with

yum install openssl-devel

find_package(OpenSSL REQUIRED)
if (OPENSSL_FOUND)
message(STATUS "Found OpenSSL ${OPENSSL_VERSION}")
else()
message(STATUS "OpenSSL Not Found")
endif()

I got following message:

-- Found OpenSSL 1.0.2s

However, I got following error when I include openssl header file in my project

fatal error: openssl/core_names.h: No such file or directory

How can I resolve this error?


Solution

  • I guess you might forget to add the following in your CMakeLists.txt

    target_link_libraries(your_executable
        PRIVATE
            openssl
    

    It does populate include directories of your target with path to include folder of openssl library, so the header can be found. You can check if this is your problem by adding

    set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
    

    this will generate compile_commands.json file into your build folder, which contains build commands - please check if include folder of openssl library is passed as -I argument to your compiler (I assume you are using GCC, so -I argument passes include search paths