title: Undefined reference with boost asio ssl
body: <p>I read a few questions and tried their suggestions but did not work for me.</p>
  
  <p>I'm trying to build a program that uses <code>#include &lt;boost/asio/ssl.hpp&gt;</code> header using CMake. My CMakeLists.txt file is:</p>
  
  <pre><code>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})
  </code></pre>
  
  <p>When I compile this (using <code>cmake .</code> followed by <code>ninja</code>) I get a whole lot of undefined reference errors related to SSL. After reading several questions, I tried something like</p>
  
  <pre><code>set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -crypto -ssl")
  </code></pre>
  
  <p>However, then I get the error:</p>
  
  <pre><code>clang-9: error: unknown argument '-crypto'; did you mean '-mcrypto'?
  clang-9: error: unknown argument: '-ssl'
  </code></pre>
  
  <p>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:</p>
  
  <p>cmake_minimum_required(VERSION 3.16)</p>
  
  <pre><code>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})
  </code></pre>