【问题标题】:boost lib error in netbeans提升netbeans中的lib错误
【发布时间】:2017-05-29 00:10:12
【问题描述】:

我从项目中剥离了所有类,留下了三个这样的错误:

error_code.hpp:222: undefined reference to `boost::system::generic_category()

使用 Netbeans IDE
单击文件 -> 项目属性 -> 链接器
在库旁边,添加了 libboost_system.so

它摆脱了对 boost::system::generic_category() 的三个未定义引用

现在它给出了:

CLEAN SUCCESSFUL (total time: 123ms)
cd '/home/michaeleric/NetBeansProjects/NNW'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/michaeleric/NetBeansProjects/NNW'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/nnw
make[2]: Entering directory `/home/michaeleric/NetBeansProjects/NNW'
mkdir -p build/Debug/GNU-Linux/_ext/d028d44d
rm -f "build/Debug/GNU-Linux/_ext/d028d44d/CGrid.o.d"
g++    -c -g -MMD -MP -MF "build/Debug/GNU-Linux/_ext/d028d44d/CGrid.o.d" -o build/Debug/GNU-Linux/_ext/d028d44d/CGrid.o ../../Desktop/NN_22_05_17/CGrid.cpp
mkdir -p dist/Debug/GNU-Linux
g++     -o dist/Debug/GNU-Linux/nnw build/Debug/GNU-Linux/_ext/d028d44d/CGrid.o -L/usr/include/boost -lboost_system
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux/nnw] Error 1
make[2]: Leaving directory `/home/michaeleric/NetBeansProjects/NNW'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/michaeleric/NetBeansProjects/NNW'
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 6s)

这个错误是什么意思以及如何解决?

休息需要的类

#include </usr/include/boost/thread/thread.hpp>
#include </usr/include/boost/thread/xtime.hpp>

#include </usr/include/boost/iostreams/write.hpp>

#define byte unsigned char
#define Thread boost::thread

class CGrid
{

    Thread* GetThread();

    bool SetThread(Thread* thread);

};

【问题讨论】:

  • 你的程序没有main函数。
  • 谢谢亨利。我“应该”知道
  • 如果您喜欢我的回答并且它对您有帮助,请考虑投票(通过单击分数旁边的箭头)和/或将其标记为已接受的答案(通过单击复选标记 ✓)。

标签: c++ boost netbeans


【解决方案1】:

如果我编译这个

g++ test.cpp -lboost_system

我得到相同的链接器错误

/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'

但是,如果我添加一个空的 main 函数,它编译得很好。 (我还用typedef 替换了你丑陋的#define。)

#include </usr/include/boost/thread/thread.hpp>
#include </usr/include/boost/thread/xtime.hpp>

#include </usr/include/boost/iostreams/write.hpp>

typedef unsigned char byte;
typedef boost::thread Thread;

class CGrid
{

    Thread* GetThread();

    bool SetThread(Thread* thread);

};

int main() {}

如果这是一个目标文件并且main 在另一个翻译单元中,请使用-c 参数对其进行编译:

g++ -c test.cpp -lboost_system

【讨论】:

  • 我没有收到“未定义的对 `main' 的引用”错误。想知道为什么#define 很丑?
  • @michaeleric 也许您有不同版本的链接器。关于#defineAre typedef and #define the same in c?
猜你喜欢
  • 1970-01-01
  • 2021-04-20
  • 2015-02-05
  • 2015-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-21
相关资源
最近更新 更多