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

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

Open
Anaphory opened this issue Jun 19, 2022 · 1 comment
Open

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

Anaphory opened this issue Jun 19, 2022 · 1 comment
Assignees
Labels
acknowledged The issue is being worked on bug Something isn't working

Comments

@Anaphory
Copy link

Anaphory commented Jun 19, 2022

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.

@Anaphory Anaphory added the bug Something isn't working label Jun 19, 2022
@filipdutescu filipdutescu self-assigned this Dec 16, 2022
@filipdutescu filipdutescu added the acknowledged The issue is being worked on label Dec 16, 2022
@filipdutescu filipdutescu changed the title [BUG] [BUG] Error linking to Conan-installed Boost Dec 16, 2022
@filipdutescu
Copy link
Owner

Hey, thanks a lot for submitting this issue and I am very grateful for the kind words! I am unsure as to why you encountered the issue and will try to replicate it myself to figure out a solution. It might be an oversight on my side and you might need to use conan_target_link_libraries(${PROJECT_NAME}).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acknowledged The issue is being worked on bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants