Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linker error: undefined reference to `OPENSSL_init_ssl' #110

Open
GSuggitt opened this issue Jan 15, 2021 · 1 comment
Open

linker error: undefined reference to `OPENSSL_init_ssl' #110

GSuggitt opened this issue Jan 15, 2021 · 1 comment

Comments

@GSuggitt
Copy link

I am building in a Debian docker container.

I build with:

RUN apt-get -y install zlib1g-dev g++ cmake doxygen graphviz libboost-all-dev libssl-dev

WORKDIR /source
RUN git clone https://github.com/jgaa/restc-cpp.git

WORKDIR /source/restc-cpp/dbuild
RUN cmake ..
RUN make

which leaves the includes under /source/restc-cpp/include.

My source file is:

#include <restc-cpp/restc-cpp.h>
int main(int argc, char *argv[]) 
{
    auto rest_client = restc_cpp::RestClient::Create();
}

I set my include search path in my CMakelist.txt file with:
include_directories(MyProject PRIVATE /source/restc-cpp/include)

But when I compile, I get the error: cannot find "rest-cpp/config.h" needed by <restc-cpp/restc-cpp.h>

Well I found it in restc-cpp/dbuild/generated-include/restc-cpp/config.h

So I copied it (and export.h) into /source/restc-cpp/include/restc-cpp/

And now it compiles but I get a link error: undefined reference to `OPENSSL_init_ssl'

My CMakelist.txt file is:

cmake_minimum_required(VERSION 2.8)

project(MyProject)

set(SOURCES 
    ${CMAKE_CURRENT_SOURCE_DIR}/test/test_rest.cpp
)

add_executable(MyProject ${SOURCES} )

set_target_properties(MyProject PROPERTIES
                        OUTPUT_NAME testrest
                      )

include_directories(MyProject PRIVATE /source/restc-cpp/include)

set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
ADD_DEFINITIONS(-DBOOST_COROUTINE_NO_DEPRECATION_WARNING)

target_link_libraries(MyProject /source/restc-cpp/lib/librestc-cpp.a)

#the following are required for restc-cpp
#----------------------------------------
target_link_libraries(MyProject z)
target_link_libraries(MyProject crypto)
target_link_libraries(MyProject ssl)
target_link_libraries(MyProject boost_system )
target_link_libraries(MyProject boost_program_options )
target_link_libraries(MyProject boost_filesystem )
target_link_libraries(MyProject boost_date_time )
target_link_libraries(MyProject boost_context )
target_link_libraries(MyProject boost_coroutine ) 
target_link_libraries(MyProject boost_chrono )
target_link_libraries(MyProject boost_log )
target_link_libraries(MyProject boost_thread)
target_link_libraries(MyProject boost_log_setup )
target_link_libraries(MyProject boost_regex )
target_link_libraries(MyProject boost_atomic )
target_link_libraries(MyProject pthread)

I believe the crypto library should supply this reference, so I don't see what I am doing wrong

@jgaa
Copy link
Owner

jgaa commented Feb 18, 2021

It's simpler probably to just include the project into your own cmake project. You can see how it can be done here:

https://github.com/jgaa/k8deployer/blob/b36a6c4b542275f7c2e499da7304637a927106cb/cmake/external-projects.cmake#L12
https://github.com/jgaa/k8deployer/blob/b36a6c4b542275f7c2e499da7304637a927106cb/CMakeLists.txt#L65

You can also make and make install, to copy the headers and libraries into /usr/local/...

If you want me to take a look at your current problem, can you create a public repository with it>? Than I can take a look and provide a PR if I find a simple solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants