"boost/filesystem.hpp" 这个文件依赖于boost_system,编译的时候,需要 -lboost_system选项,但是你的编译选项里头已经指定该选项,为什么还会出现链接错误呢。我也纳闷了半天,后来发现,原来是-l选项的顺序问题。在g++的man帮助信息里面,我发现了下面的话:
引用It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o. If bar.o refers to functions in z, those functions may not be loaded.读完这段话,应该就明白出错原因了。所以,解决方案就是用下面的命令来编译: