0

I'm doing C++ using libcURL. I got the task to test functions in Travis CI. So I used .travis.yml to get libcurl-dev and libssl-dev to connect to the project. I installed them and checked cURL configuration:
SSL support: enabled (OpenSSL)

But as I was trying to make main test file i got list of errors (example)

`Linking CXX executable ../bin/TechProject_example
/usr/local/lib/libcurl.a(libcurl_la-openssl.o): In function ossl_recv:
openssl.c:(.text+0xf3): undefined reference to ERR_clear_error
openssl.c:(.text+0x11c): undefined reference to SSL_read
openssl.c:(.text+0x163): undefined reference to SSL_get_error`

and so on...

The only thing I was able to check is that libcurl is working properly. I placed --without-ssl flag and got protocol error.

Also I used

`- sudo ln -fs /usr/lib/libcurl.so.4 /usr/local/lib/` 

to avoid cmake error. (I'm not very good at UNIX command, so this can be a problem)

So how should properly connect openSSL to C++ project that has <curl/curl.h> ?

EDIT: Here is CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)

project (TechProject)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(HEADERS ${PROJECT_SOURCE_DIR}/include/testclass.h)
set(HEADERS ${PROJECT_SOURCE_DIR}/include/catch.hpp)
set(SOURCES ${PROJECT_SOURCE_DIR}/sources/testclass.cpp)



set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)


include_directories(${PROJECT_SOURCE_DIR}/include)

add_library (${PROJECT_NAME} STATIC ${SOURCES})

add_subdirectory(example)
add_subdirectory(tests)

find_library(FOO_LIB libcurl.a)
target_link_libraries(TechProject "${FOO_LIB}")

And CMakeLists.txt in tests subdir:

cmake_minimum_required(VERSION 2.8)

set(TESTS_FOR_PROJECT TechProject)

project(${TESTS_FOR_PROJECT}_tests)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF)

file(GLOB ${PROJECT_NAME}_sources "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")

find_package(${TESTS_FOR_PROJECT})
include_directories(${${TESTS_FOR_PROJECT}_INCLUDE_DIRS}})


include_directories(${CPM_INCLUDE_DIRS})

add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_sources} ${${PROJECT_NAME}_headers})


target_link_libraries(${PROJECT_NAME} ${TESTS_FOR_PROJECT})


add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD
               COMMAND ${CMAKE_COMMAND} -E copy_directory
                   ${CMAKE_CURRENT_SOURCE_DIR}/fixtures $<TARGET_FILE_DIR:${PROJECT_NAME}>)

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${PROJECT_NAME} -s -r compact WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
A. Ko
  • 1
  • 3
  • Without the CMakeLists.txt file it is not easy/possible to get into details. Please provide the file. BTW: Don't know whether your system is still working, but the `ln` command you provided kills the `/usr/local/lib` directory. The right is `sudo ln -s /usr/lib/libcurl.so.4 /usr/local/lib/libcurl.so` – Th. Thielemann May 28 '17 at 15:01
  • I have edited the question by providing CMakeLists – A. Ko May 28 '17 at 15:56
  • @Th.Thielemann and I also found the way to avoid ln -fs command – A. Ko May 28 '17 at 15:58
  • You should use an RPATH for OpenSSL and cURL. You *should not* build OpenSSL with Cmake. You *must* build OpenSSL with a C compiler, not a C++ compiler. Also see [Build OpenSSL with RPATH?](https://stackoverflow.com/q/29858870/608639) and [Compilation and Installation | Using RPATHs](https://wiki.openssl.org/index.php/Compilation_and_Installation#Using_RPATHs) on the OpenSSL wiki. Finally, see [Linking OpenSSL libraries to a program](https://stackoverflow.com/q/4352573/608639). Order of the libraries matters because LD is a single pass linker. – jww May 28 '17 at 18:26
  • Please show your link command for the program `TechProject`. The linker is `ld`, so the link command should be the one that starts with `ld ...`. Cmake hides the critical information from you, so you will need to figure out a way to get to it. – jww May 28 '17 at 18:36

0 Answers0