使用Windows / Cygwin在Netbeans中使用gnuplot-iostream库编译时遇到的问题

时间:2014-06-23 19:41:08

标签: c++ boost netbeans cygwin gnuplot

我试图在Netbeans中使用带有Windows / Cygwin的库gnuplot-iostream,但仅在我的源代码中包含它会导致编译问题。我已经使用Cygwin界面下载了boost。然而,我得到的信息是:

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

除了包含它之外,我还没有提到图书馆:

#include "gnuplot-iostream.h"

我也无法找到任何关于此错误的提及。有人知道我做错了吗?

由于

2 个答案:

答案 0 :(得分:1)

  

我相信你说的问题是没有正确链接到boost库,对吗?

你看到-lcygcurl-4?这实际上将您的代码与curl实现相关联。图书馆搜索-L<xxx>的图片看起来很好,但是您仍然需要指定在那里找到的特定库,并且需要链接到您的程序。

如果您使用-l<yyy>选项指定关联其他库,则会在实际构建环境中将其解析为lib<yyy>.a(或lib<yyy>.lib)。

如上所述,仅仅应用#include <yyy.hpp>并不足以告诉工具链(链接器)实际实现的来源。添加库的方式与使用IDE / build系统添加cygcurl-4 libraray的方式相同。

从评论中转移讨论,使其成为一个答案(我知道的很差,而且我已经标记了重复项。这只是因为这个简单的澄清不太适合评论) < / p>

答案 1 :(得分:1)

如果其他人需要,请保留此注册。要解决此问题,需要在链接器中添加-lboost_system-mt。要在Netbeans中执行此操作,必须右键单击项目,选择“属性”,然后转到“链接器”(位于“构建”下)。编译行会有一个选项。应该在那里添加标志。