0

I am trying the asio c14 ssl client example.

Giving the following CMakeLists.txt

cmake_minimum_required(VERSION 3.19.0)
project(TlsClient)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(ASIO_dir ${PROJECT_SOURCE_DIR}/asio-1.18.1)
# Imports pthread for Asio
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)
# Executable 
add_executable(TlsClient client.cpp)

#include asio
target_include_directories(TlsClient PUBLIC
    "${ASIO_dir}/include"
)

target_link_libraries( TlsClient ${CMAKE_USE_PTHREADS_INIT} )

if(${OPENSSL_FOUND})
message(NOTICE "OpenSSL library version ${OPENSSL_VERSION}" )
target_include_directories(TlsClient PUBLIC ${OPENSSL_INCLUDE_DIR})
target_link_libraries( TlsClient ${OPENSSL_SSL_LIBRARY} ${CMAKE_DL_LIBS})
else()
message(NOTICE "Unable to find OpenSSL library")
endif()

The cmake yields the following error

[main] Configuring folder: TLS 
[proc] Executing command: /snap/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/bin/gcc-10 -DCMAKE_CXX_COMPILER:FILEPATH=/bin/g++-10 -H/home/r0n9/Code/cpp/TLS -B/home/r0n9/Code/cpp/TLS/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] OpenSSL library version 1.1.1f
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: /home/r0n9/Code/cpp/TLS/build
[main] Building folder: TLS clean
[build] Starting build
[proc] Executing command: /snap/bin/cmake --build /home/r0n9/Code/cpp/TLS/build --config Debug --target clean --
[build] Build finished with exit code 0
[main] Building folder: TLS 
[build] Starting build
[proc] Executing command: /snap/bin/cmake --build /home/r0n9/Code/cpp/TLS/build --config Debug --target all -- -j 18
[build] [ 50%] Building CXX object CMakeFiles/TlsClient.dir/client.cpp.o
[build] [100%] Linking CXX executable TlsClient
[build] /usr/bin/ld: cannot find -l1 <----Not sure why this library is required
[build] collect2: error: ld returned 1 exit status
[build] make[2]: *** [CMakeFiles/TlsClient.dir/build.make:104: TlsClient] Error 1
[build] make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/TlsClient.dir/all] Error 2
[build] make: *** [Makefile:103: all] Error 2
[build] Build finished with exit code 2

Update1: The output of

message(NOTICE "OpenSSL library version [${OPENSSL_VERSION}], [${OPENSSL_INCLUDE_DIR}], [${OPENSSL_LIBRARIES}], [${CMAKE_DL_LIBS}]" )

is

[cmake] OpenSSL library version [1.1.1f], [/usr/include], [/usr/lib/x86_64-linux-gnu/libssl.so;/usr/lib/x86_64-linux-gnu/libcrypto.so], [dl]
r0n9
  • 2,505
  • 1
  • 29
  • 43
  • Try to print out values of `OPENSSL_*` and `CMAKE_DL_LIBS` variables to see what they are. – vahancho Mar 10 '21 at 09:46
  • 1
    A thread-related variable for link with is `CMAKE_THREAD_LIBS_INIT`. But you use the variable `CMAKE_USE_PTHREADS_INIT`, which is actually a **flag** indicating whether "thread library is pthread compatible" ([documentation](https://cmake.org/cmake/help/latest/module/FindThreads.html)). – Tsyvarev Mar 10 '21 at 09:54

0 Answers0