【问题标题】:Problems compiling using gnuplot-iostrem library in Netbeans with Windows/Cygwin [duplicate]使用 Windows/Cygwin 在 Netbeans 中使用 gnuplot-iostrem 库进行编译时出现问题 [重复]
【发布时间】:2014-08-13 23:18:25
【问题描述】:

我正在尝试在带有 Windows/Cygwin 的 Netbeans 中使用库 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"

我也找不到任何有关此错误的信息。有人知道我做错了什么吗?

谢谢

【问题讨论】:

  • '除了包含它之外,我没有对库进行任何引用:' 那么这可能很好地回答了你的问题:What is an undefined reference/unresolved external symbol error and how do I fix it?
  • 其实我不相信包含一个不会被使用的库会导致任何错误。只是为了确保我尝试编译 gnuplot-iostream 主页上的第一个示例,但仍然得到基本相同的错误。
  • '其实我不相信包含一个不会被使用的库......'链接器明确声明它被使用来自/usr/include/boost/system/error_code.hpp,您的代码 'infected' 带有此标头!那么为什么不简单地为您的链接器添加一个-lboost_system 选项呢?
  • 我对库的唯一提及是#include 命令。无论如何,我如何添加这个-lboost_system 选项?它应该怎么做?抱歉,我对 C++(和 Netbeans)完全陌生。
  • 你没有用#include 声明来编造任何关于'只是提到'它的自动链接。如果它不是一个明确声明的 header only 库,您需要指定从何处获取包含的头文件中声明的实现。再次转到我在第一条评论中给你的那个链接,以获得更深入的解释。

标签: c++ boost netbeans cygwin gnuplot


【解决方案1】:

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

你看到-lcygcurl-4了吗?这实际上将您的代码与curl 实现联系起来。库搜索-L<xxx> 用于提升的路径看起来不错,但您仍然需要指定在那里找到的特定库并需要链接到您的程序。

如果您使用-l<yyy> 选项指定链接其他库,这些库将被解析为在您的实际构建环境中查找lib<yyy>.a(或lib<yyy>.lib)。

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

从 cmets 转移讨论,以使这个答案成为答案(我知道的很差,我已经标记了重复项。只是因为这个简单的澄清显然不太适合评论)

【讨论】:

    【解决方案2】:

    只是为了在其他人需要时保持注册。为了解决这个问题,需要在链接器中添加一个-lboost_system-mt。要在 Netbeans 中这样做,必须右键单击项目,选择 Properties,然后转到 Linker(在 Build 下)。编译行将有一个选项。应该在此处添加标志。

    【讨论】:

    • 是的,这对于 OP 显然出来的最终解决方案来说是一个好点。
    猜你喜欢
    • 2014-08-11
    • 1970-01-01
    • 2013-08-13
    • 1970-01-01
    • 1970-01-01
    • 2013-02-10
    • 1970-01-01
    • 2013-02-01
    • 2018-05-22
    相关资源
    最近更新 更多