Skip to content

[BUG] Error linking to Conan-installed Boost  #40

Open
@Anaphory

Description

@Anaphory

I am probably doing something wrong, because I'm very new to C++ and wanted to start from a sensible template. (This template is awesome, by the way! It got me started very well, and I am much happier with the state of my learning project than I could imagine if I started from scratch. I just like myself a good build/package structure.)

Describe the bug

Following the instructions, I had a Conan provided library not linked, so I got undefined reference to boost::read_graphml(std::istream&, boost::mutate_graph&, unsigned long)' from ld.

To Reproduce
Steps to reproduce the behavior:

I am trying to play around with graphs, so I included Conan in the cmake configuration

option(${PROJECT_NAME}_ENABLE_CONAN "Enable the Conan package manager for this project." ON)

and changed the Conan.cmake to include boost

  set(${PROJECT_NAME}_CONAN_REQUIRES "boost/1.79.0")

I set the project to compile executables and wrote a small main.cpp to load a graph from a GraphML file

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_concepts.hpp>
#include <boost/graph/graphml.hpp>
#include <ios>
#include <list>

#include "cmcmc/tmp.hpp"

using namespace std;

int main(int argc, char *argv[])
{
  using Graph = boost::adjacency_list<>;
  Graph g;
  boost::dynamic_properties dp{ boost::ignore_other_properties };

  if (argc > 1)
  {
    ifstream in{ argv[1] };
    boost::read_graphml(in, g, dp, 0);
  }
}

💥

/usr/bin/ld: CMakeFiles/CMCMC.dir/src/main.cpp.o: in function `void boost::read_graphml<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::no_property, boost::no_property, boost::no_property, boost::listS> >(std::istream&, boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::no_property, boost::no_property, boost::no_property, boost::listS>&, boost::dynamic_properties&, unsigned long)':
/home/anaphory/.conan/data/boost/1.79.0/_/_/package/1671931156455a119d7c3f14d951ac5fdbc5cd10/include/boost/graph/graphml.hpp:229: undefined reference to `boost::read_graphml(std::istream&, boost::mutate_graph&, unsigned long)'
collect2: error: ld returned 1 exit status

Expected behavior

I thought with this setup, Conan would pull in Boost to a known location, and cmake would ensure it gets linked to. (I had some version of Boost headers available before installing Boost using Conan, so that may have complicated the impression I got.)

Workaround

I added conan_target_link_libraries(${PROJECT_NAME}) as last line to my CMakeList.txt and it works fine. So I assume the issue is more how I use the template and associated software – which, fair, I don't really understand well enough – and not an actual issue with the template, but maybe it is an issue worth pointing out?

Environment

I'm happy to provide version strings and other similar items, I just don't know what is useful.

Metadata

Metadata

Assignees

Labels

acknowledgedThe issue is being worked onbugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions