2

I am working on a little software that needed a small server that listens to http requests. Unfortunately, the productive server uses https only, so the requests fail. I've search the web and found this example: http://www.boost.org/doc/libs/1_65_0/doc/html/boost_asio/example/cpp03/ssl/server.cpp

I tried my best to apply the required changes. But I can't compile it. I am on a MacOS machine, but the Server is a Ubuntu Server. I installed OpenSSL via brew.

The compilation fails at the linking process:

[ 98%] Linking CXX executable GpdServer
Undefined symbols for architecture x86_64:
  "_ERR_remove_thread_state", referenced from:
      boost::asio::ssl::detail::openssl_init_base::do_init::~do_init() in main.cpp.o
      boost::asio::ssl::detail::openssl_init_base::do_init::~do_init() in TcpServer.cpp.o
      boost::asio::ssl::detail::openssl_init_base::do_init::~do_init() in TcpConnection.cpp.o
  "_TLSv1_1_client_method", referenced from:
      boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in TcpServer.cpp.o
  "_TLSv1_1_method", referenced from:
      boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in TcpServer.cpp.o
  "_TLSv1_1_server_method", referenced from:
      boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in TcpServer.cpp.o
  "_TLSv1_2_client_method", referenced from:
      boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in TcpServer.cpp.o
  "_TLSv1_2_method", referenced from:
      boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in TcpServer.cpp.o
  "_TLSv1_2_server_method", referenced from:
      boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in TcpServer.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [GpdServer] Error 1
make[1]: *** [CMakeFiles/GpdServer.dir/all] Error 2
make: *** [all] Error 2

The TcpConnection files that cause this issue are here: https://github.com/cwansart/gpd/blob/master/src/TcpServer.h https://github.com/cwansart/gpd/blob/master/src/TcpServer.cpp

My build system is CMake. Including it works fine.

What am I doing wrong? How do I fix this?

  • 2
    Boost ASIO is not a header-only library, especially with the SSL components. You need to actually *link* with a library for it to work. – Some programmer dude Aug 25 '17 at 09:34
  • I thought I did, see Line 36 https://github.com/cwansart/gpd/blob/master/CMakeLists.txt#L36 –  Aug 25 '17 at 09:37
  • 2
    The line you link to is the OpenSSL libraries, I'm talking about one of the Boost libraries. Add `asio` to the `find_package(Boost)` command, that will add the Boost ASIO libraries to `Boost_LIBRARIES`. – Some programmer dude Aug 25 '17 at 09:39
  • Oh. Since it was in the boost-system package on ubuntu, I thought this would work. https://stackoverflow.com/questions/2078898/using-boost-asio-in-cmake <-- according to this I just used system. Adding asio doesn't work. You sure that this is a component I can "find"? –  Aug 25 '17 at 09:43
  • 1
    Sorry but it seems that I'm wrong. Boost ASIO *itself* is a header-only library, so you should not have it in the `find_package` command. I've never used the SSL capabilities of ASIO (Boost or standalone) myself so I'm afraid I can't help you further. – Some programmer dude Aug 25 '17 at 09:50
  • 1
    Okay, thank you anyways. It seeems to be an issue with the mac. On Linux it works. I'll answer this question in a minute to elaborate it. Damn mac.. –  Aug 25 '17 at 09:59

1 Answers1

0

As it turns out the macOS was the issue. I installed OpenSSL via brew. First, my CLion/CMake didn't find it, so I added an if to check if its an Apple PC. In that case I set the path manually to the path brew gave me. Now, for some reason the linking doesn't work.

On Linux with libssl-dev there are no issues.

  • Did you ever fix this issue on the mac? – Luis Sep 08 '18 at 23:02
  • I actually fixed it by linking on the CMakeLists.txt like this: target_link_libraries(executable_name pthread ssl crypto boost_system)... in addition to specifying include and link directories. – Luis Sep 09 '18 at 16:07