平台:ubuntu12.04LTS,boost1.53
1、应该用g++编译,而不是cc,本来想亲自解释一下的,然后发现有人写过了,,简单来说,cc是指向gcc的符号链接,而gcc不能处理C++的linking.所以通常编译命令就是g++ myfile.cpp -o myfile,偶尔要链接额外的库,见第2条
还有一段觉得讲得不错()
CC
is an environment variable referring to the system's C compiler. What it points to (libraries accessible, etc) depend on platform. Often it will point to/usr/bin/cc
, the actual c complier (driver). On linux platforms,CC
almost always points to/usr/bin/gcc
.
gcc
is the driver binary for the GNU compiler collection. It can compile C, C++, and possibly other languages; it determines the language by the file extension.
g++
is a driver binary likegcc
, but with a few special options set for compiling C++. Notably (in my experience),g++
will link libstdc++ by default, whilegcc
won't.
2、有时会出现一大堆类似这种错误:undefined reference to boost::system::system_category()...
对于这个,可以编译时链接boost_system库,即-lboost_system;其他的类似处理