2

The boost library works fine, except for this function boost::read_graphml() it say that there is a problem

#include <iostream>
#include <iostream>
#include <string>
#include <fstream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphml.hpp>
int main()
{
using namespace boost;
typedef adjacency_list<vecS, vecS, undirectedS, no_property > Graph;
typedef dynamic_properties Dproperty;
Graph g;
Dproperty dp;

std::string file = "test.graphml";
std::ifstream t(file.c_str());
if (!t.is_open())
{
    std::cout << "loading file failed." << std::endl;
    throw "Could not load file.";
}

read_graphml(t, g, dp);

return 0;
}

the error is :

error LNK2019: unresolved external symbol "void __cdecl boost::read_graphml(class std::basic_istream<char,struct std::char_traits<char> > &,class boost::mutate_graph &,unsigned int)" (?read_graphml@boost@@YAXAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAVmutate_graph@1@I@Z) referenced in function "void __cdecl boost::read_graphml<class boost::adjacency_list<struct boost::vecS,struct boost::vecS,struct boost::directedS,struct boost::property<enum boost::vertex_name_t,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::no_property>,struct boost::no_property,struct boost::no_property,struct boost::listS> >(class std::basic_istream<char,struct std::char_traits<char> > &,class boost::adjacency_list<struct boost::vecS,struct boost::vecS,struct boost::directedS,struct boost::property<enum boost::vertex_name_t,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::no_property>,struct boost::no_property,struct boost::no_property,struct boost::listS> &,struct boost::dynamic_properties &,unsigned int)" (??$read_graphml@V?$adjacency_list@UvecS@boost@@U12@UdirectedS@2@U?$property@W4vertex_name_t@boost@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Uno_property@2@@2@Uno_property@2@U52@UlistS@2@@boost@@@boost@@YAXAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV?$adjacency_list@UvecS@boost@@U12@UdirectedS@2@U?$property@W4vertex_name_t@boost@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Uno_property@2@@2@Uno_property@2@U52@UlistS@2@@0@AAUdynamic_properties@0@I@Z)
1>D:\_example.exe : fatal error LNK1120: 1 unresolved externals
sehe
  • 374,641
  • 47
  • 450
  • 633
Jon.Snow
  • 33
  • 4

1 Answers1

1

You need to

  • link to the compiled Boost Graph library or
  • include BOOST_DIR/libs/graph/src/graphml.cpp into the build.

See also: What is an undefined reference/unresolved external symbol error and how do I fix it?

sehe
  • 374,641
  • 47
  • 450
  • 633
  • I suppose linking to the graph library should also work.PS: Yeah, according to the [docs](http://www.boost.org/libs/graph/doc/read_graphml.html): "To use the GraphML reader, you will need to build and link against the "boost_graph" library." – llonesmiz Dec 18 '15 at 22:12
  • @cv_and_he I didn't know that existed. But yeah, that would work :) It's arguably better. But IMO Boost Graph compiled components are so isolated and tiny, I'd usually want to link them statically – sehe Dec 18 '15 at 22:14
  • do you know how to build and link against the "boost_graph" library – Jon.Snow Dec 18 '15 at 22:22
  • Yes, and so do you: http://www.boost.org/doc/libs/1_59_0/more/getting_started/windows.html. Really. Just drop in the cpp file in this case. (Be sure to keep it in synch with boost version if you do) – sehe Dec 18 '15 at 22:24
  • did it but still the same problem, no changes – Jon.Snow Dec 18 '15 at 22:58
  • Tell us _what_ you have done. Or get someone to help you out in person. This is not too hard. But it's hard to see your project definitions from here – sehe Dec 18 '15 at 22:59
  • I linked to the boost lib and included the graphml.cpp into the build, and added #include to the main project, and now it works. Thanks – Jon.Snow Dec 18 '15 at 23:23
  • Don't include the `.cpp` with the preprocessor. Either link the library **or** include `graphml.cpp` into the build – sehe Dec 18 '15 at 23:36
  • @Mohav In case you are interested, you can download the binaries from [here](http://sourceforge.net/projects/boost/files/boost-binaries/1.60.0/) (the versions with `msvc-12` are for Visual Studio 2013). There are versions for 32 and 64 bits, so choose the one you need (or both). Keep in mind that once extracted the files will be several gigabytes(2.10 GB for 1.59 for VS2015 32 bits). Once you have your files extracted you'll need to add the library path to "VC++ directories/Library directories" and the autolink will choose the appropriate library to link automatically. – llonesmiz Dec 19 '15 at 06:13