0

Setup: library com uses library http which in the namespace http contains class ConnectionPool. ConnectionPool has method boost::network::http::client::response post(boost::network::http::client::request req);

where http_request is boost::network::http::client::request

env:

c++ (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
GNU Make 4.1
Cmake 3.15.3

Files:

  • where is how Boost is included on paste bin

This is how the function is declared

boost::network::http::client::response
    post(boost::network::http::client::request req, unsigned timeoutMs);

post() is called like this in com

connectionPool.post(http_request, 4000);

I have a strange problem with CMake configuration: when using post in com linker (ld) returns 1 with error:

undefined reference to http::HTTPConnectionPool::post(boost::network::http::basic_request<boost::network::http::tags::http_default_8bit_udp_resolve>)'

However if I remove boost request from the signature of post, everything compiles and works just fine. From that I can conclude that the problem is in linking boost to the http library, but I'm unable to find it, so here are CMakeFile's

http/CMakeLists.txt

aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} http_srcs)
add_library(http ${http_srcs})
target_link_libraries(http PRIVATE pthread ${Boost_LIBRARIES} cppnetlib-uri)

com/CMakeFiles.txt

aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} com_srcs)
add_library(com ${com_srcs})
target_link_libraries(com PRIVATE jsoncpp cppnetlib-uri ${OpenCV_LIBRARIES} ${Boost_LIBRARIES})

linking them together in main/CMakeLists.txt

# some code skipped there
target_link_libraries(main
                      config api rdm anm web com http dab log jsoncpp
                      ${Boost_LIBRARIES}
        )

I have tried already:

  1. renaming namespace from http to something else to check if there is possible collision
  2. link http to com in com/CMakeLists.txt
  3. change order in main/CMakeLists.txt target_link_libraries()
  4. this answer https://stackoverflow.com/a/12205075/6429920

Another functions and constuctors from ConnectionPool work fine, the problem occurs only when using boost request as one of the parameters.

The strange thing is function with the same signature works in com.

gasabr
  • 55
  • 3
  • 9
  • 1
    Your example is not complete, e.g. the code invoking `http::HTTPConnectionPool::post` and header containing `http::HTTPConnectionPool::post` might be useful. For now I can just guess that `${Boost_LIBRARIES}` doesn't contain the boost libraries you need to link with (maybe you didn't call `find_package` correctly). – pptaszni Feb 05 '20 at 09:17
  • thank you for comment! added the code you asked for. I will take a look at `Boost_LIBRARIES`, although they should be same for both cases when `post()` is in com and or in http – gasabr Feb 05 '20 at 12:45
  • Can you show the code used to find Boost? A `find_package` call? Also, why do you use `Boost_LIBRARIES` and `Boost_LIBS`? Do these each contain different libraries? – Kevin Feb 05 '20 at 12:55
  • I was trying different variables for boost libs and forgot to change it back before posting, should be `${Boost_LIBRARIES}` everywhere, fixed it in the edit. – gasabr Feb 05 '20 at 13:01
  • OK, so the signature of the function `post` (accepting 2 arguments) in the header you posted (it should be included in the question, not in pastebin) does not match the linker error msg (accepting one argument). Where do you have the implementation of your method `post`? – pptaszni Feb 05 '20 at 13:31
  • sorry, I made a mess trying everything possible to fix this error, when signature match perfectly there is still this error, I will fix the question now – gasabr Feb 05 '20 at 13:37
  • The linker error still indicates that there is a function `post` accepting one argument used somewhere. Where is this coming from? Unless you are still using a one-argument version somewhere (as the top of your question post claims)? This is difficult to follow without a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) posted within your question post. – Kevin Feb 05 '20 at 18:13

0 Answers0