0

First I have setup my project with the following command and files at the root:

conan install ./ && cmake CMakeList.txt

conanfile.txt

[generators]
cmake

[requires]
boost/1.68.0@conan/stable

[options]
boost:shared=True

[imports]

CmakeList.txt

cmake_minimum_required(VERSION 3.10)
project(app CXX)

include(conanbuildinfo.cmake)
conan_basic_setup()

set(CMAKE_C_FLAGS  "${CMAKE_C_FLAGS} -Wall")
add_definitions("-std=c++11")

add_executable(app src/main.cpp)

target_link_libraries(app ${CONAN_LIBS})

Everything is ok until I try to compile the project using make. Here's my main.cpp

#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/string.hpp>
int main(int ac, char *args[]) {
    std::ofstream ofs("test");
    boost::archive::text_oarchive writer(ofs);
}

When compiling, im getting an undefined reference:

CMakeFiles/app.dir/src/main.cpp.o : in function « void boost::archive::save_access::save_primitive<boost::archive::text_oarchive, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(boost::archive::text_oarchive&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) » :
main.cpp:(.text._ZN5boost7archive11save_access14save_primitiveINS0_13text_oarchiveENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEvRT_RKT0_[_ZN5boost7archive11save_access14save_primitiveINS0_13text_oarchiveENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEvRT_RKT0_]+0x2b) : undefined reference to « boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) »
collect2: error: ld returned 1 exit status

I have no clue about the source of this error.. Compiler? Library Link? It's strange because I can use other features of boost, it's not working only with boost serialization...

/!\This is not a duplicate, the goal is to understand why Conan doesnt link Boost.Serialization, that should be linked.

Romain-p
  • 518
  • 2
  • 9
  • 26
  • This is clearly a usual "undefined reference..." linker error. Have you verified that this conan thing downloaded and installed correct library, that setting it up in cmake worked properly and generated compiler / linker command includes correct library location path and library to link? – user7860670 Sep 22 '18 at 14:37
  • target_link_libraries(app ${CONAN_LIBS}) should do the job.. – Romain-p Sep 22 '18 at 14:39
  • it's not a duplicate – Romain-p Sep 22 '18 at 14:45
  • `boost/archive` is called Boost.Serialization and is __not__ a header only library ( https://www.boost.org/doc/libs/1_68_0/more/getting_started/unix-variants.html ) . Have you built it (Boost) and are you linking with it? – Richard Critten Sep 22 '18 at 14:49
  • it seems you don't know Conan, everything is downloaded and linked by conan/cmake – Romain-p Sep 22 '18 at 14:50
  • But have you actually checked that it is happening? Have you at least checked that correct library is downloaded? – user7860670 Sep 22 '18 at 14:53
  • of course, it's the latest boost library (including all sub packages with shared ones) – Romain-p Sep 22 '18 at 14:57
  • As ABI of almost any C++ library depends on **C++ standard**, it seems that you need to ask Conan for the Boost library corresponded to `C++11`. Conan definitely doesn't check the line `add_definitions("-std=c++11")` (especially when it comes *after* the `conan_basic_setup()` call. This [HowTo page](https://docs.conan.io/en/latest/howtos/manage_cpp_standard.html) says that you need to pass `cppstd=11` option for `conan install`. – Tsyvarev Sep 22 '18 at 14:58
  • this option didnt solve the problem – Romain-p Sep 22 '18 at 15:11
  • Hi @Romain-p. It seems this question is not being understood here. Please submit your case as a question to Conan github issues https://github.com/conan-io/conan, and we will try to help there. Might be an issue with the Boost package, it is likely. Please include details about your platform too, OS, compiler, etc. Thanks! – drodri Sep 23 '18 at 09:28
  • yes thank you, some retards marked it as duplicate – Romain-p Oct 04 '18 at 09:39

0 Answers0