从我的终端会话:
Go Trojans >make all
g++ -static -I/usr/include/boost -I/usr/include/boost/filesystem get_sys_info.cpp
/tmp/cc6nK9EV.o: In function `__static_initialization_and_destruction_0(int, int)':
get_sys_info.cpp:(.text+0x13a): undefined reference to `boost::system::generic_category()'
get_sys_info.cpp:(.text+0x146): undefined reference to `boost::system::generic_category()'
get_sys_info.cpp:(.text+0x152): undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
make: *** [all] Error 1
Go Trojans >
导入 Boost C++ 文件系统库的 C++ 代码:
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
// Include Boost C++ libraries
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
using namespace std;
int main() {
string my_str = "This is a string.";
cout << my_str << endl;
/*
my_str = system("pwd");
my_str.append("\b\b\b\b\b\b\b\b extra");
cout << my_str << "a\b\b\b\b\b\b=" << endl;
*/
path p(".");
cout << p << "==" << endl;
return 0;
}
来自我的 Boost C++ 库所在目录的终端会话的片段。
Go Trojans >pwd
/usr/include/boost
Go Trojans >ls -al
total 1308
drwxr-xr-x 86 root root 12288 Jan 29 09:30 .
drwxr-xr-x 119 root root 20480 Feb 4 08:08 ..
...
drwxr-xr-x 5 root root 4096 Jan 29 09:30 filesystem
-rw-r--r-- 1 root root 1340 Jan 5 2012 filesystem.hpp
如何解决未定义的引用?我是否正确导入了 Boost C++ 文件系统库?我是否也在正确编译代码?
我的错误是什么?你能帮帮我吗?
非常感谢,祝您有美好的一天!再见!