I read a few questions and tried their suggestions but did not work for me.
I'm trying to build a program that uses #include <boost/asio/ssl.hpp>
header using CMake. My CMakeLists.txt file is:
cmake_minimum_required(VERSION 3.16)
project(Test LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
add_executable(myapp
main.cpp
)
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost COMPONENTS system REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
target_link_libraries(myapp ${BOOST_LIBRARIES})
When I compile this (using cmake .
followed by ninja
) I get a whole lot of undefined reference errors related to SSL. After reading several questions, I tried something like
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -crypto -ssl")
However, then I get the error:
clang-9: error: unknown argument '-crypto'; did you mean '-mcrypto'?
clang-9: error: unknown argument: '-ssl'
The referenced question lead me the right way. For those who might get a similar issue, you need to link against OpenSSL. So the final CMakeLists.txt becomes:
cmake_minimum_required(VERSION 3.16)
project(Test LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
add_executable(myapp
main.cpp
)
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIRS})
target_link_libraries(myapp ${OPENSSL_LIBRARIES})
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost COMPONENTS system REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
target_link_libraries(myapp ${BOOST_LIBRARIES})