0

I am trying to use the library gnuplot-iostream in Netbeans with Windows/Cygwin, but merely including it in my source leads to compilation problems. I have already downloaded boost with the Cygwin interface. Yet, the message I get is:

mkdir -p dist/Debug/Cygwin_4.x-Windows
g++     -o dist/Debug/Cygwin_4.x-Windows/welcome_1 build/Debug/Cygwin_4.x-Windows/welcome.o -L../../../../../cygwin64 -L../../../../../cygwin64/lib/curl -L../../../../../cygwin64/bin -lcygcurl-4
build/Debug/Cygwin_4.x-Windows/welcome.o: In function `__static_initialization_and_destruction_0':
/usr/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:222:(.text+0x51ca): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:223:(.text+0x51d6): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:224: undefined reference to `boost::system::system_category()'
/usr/include/boost/system/error_code.hpp:224:(.text+0x51e2): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::system_category()'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/Cygwin_4.x-Windows/welcome_1.exe' failed
make[2]: *** [dist/Debug/Cygwin_4.x-Windows/welcome_1.exe] Error 1

I haven't made any reference to the library besides including it:

#include "gnuplot-iostream.h"

I also can't find any mention of this error. Does anybody know what I am doing wrong?

Thanks

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • _'I haven't made any reference to the library besides including it:'_ Then this might well answer your question: [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – πάντα ῥεῖ Jun 23 '14 at 19:45
  • Actually I don't believe including a library which is not going to be used should lead to any error. Just to be sure I tried compiling the first example on the gnuplot-iostream homepage and still got basically the same error. – user3761418 Jun 23 '14 at 19:51
  • _'Actually I don't believe including a library which is not going to be used ...'_ The linker clearly states **it is used** from `/usr/include/boost/system/error_code.hpp` where ever you had your code _'infected'_ with this header! So why not simply adding a `-lboost_system` option for your linker? – πάντα ῥεῖ Jun 23 '14 at 19:54
  • The only mention I made to the library was the `#include` command. Anyway, how do I add this `-lboost_system` option? What should it do? Sorry, but I am completely new to C++ (and Netbeans). – user3761418 Jun 23 '14 at 20:16
  • You're not making up any automatic linking about _'just mentioning'_ it with an `#include` statement. If it's not a clearly stated _header only_ library, you'll need to specify from where to get the implementations as declared in the header files included. Go to that link I gave you in my first comment again, to get some more in depth explanations. – πάντα ῥεῖ Jun 23 '14 at 20:20
  • I have read the reference. I believe you are saying the problem is with not properly linking to the `boost` libraries, correct? I have tried adding the path to their location on the linker, but still to no avail. The command now looks like this: `g++ -o dist/Debug/Cygwin_4.x-Windows/welcome_1 build/Debug/Cygwin_4.x-Windows/welcome.o L../../../../../cygwin64/boost/iostreams -L../../../../../cygwin64/boost/system -L../../../../../cygwin64/boost/filesystem -L../../../../../cygwin64/boost/utility -lcygcurl-4` (omitting the ones not from boost) – user3761418 Jun 23 '14 at 20:44
  • Just found the solution in another topic. Had to add the flag `-lboost_system-mt` to the linker. Thanks for the help. The other topic can be found here: [link](http://stackoverflow.com/questions/13467072/c-boost-undefined-reference-to-boostsystemgeneric-category) – user3761418 Jun 23 '14 at 21:52

2 Answers2

1

I believe you are saying the problem is with not properly linking to the boost libraries, correct?

You see that -lcygcurl-4? This actually links your code with the curl implementation. The library search -L<xxx> pathes you have for boost look fine, but you'll have still need to specify particular libraries found there and need being linked to your program.

If you specify linking additional libraries using the -l<yyy> option, these are resolved as looking up lib<yyy>.a (or lib<yyy>.lib) in your actual build environment.

As mentioned just applying an #include <yyy.hpp> isn't enough to tell the toolchain (linker) where the actual implementation comes from. Add the library the same way you've added that cygcurl-4 libraray with your IDE/build system.

Transferred discussion from comments, to make this an answer (poor I know and I've marked the duplicates already. It's just because this simple clarification doesn't fit a comment very well apparently)

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
1

Just to keep this registered if someone else needs it. To solve the problem it was needed to add a -lboost_system-mt in the linker. To do so in Netbeans one has to right-click on the project, choose Properties, then go to Linker (which is under Build). There will be an option for Compilation Line. The flag should be added there.