GCC不使用Boost文件夹包含标志

问题描述:

我有一个项目,其中包括使用boost 1.57的库,该库也包含在内。但是,GCC编译器(默认的Xcode CLI工具v6.0 GCC版本4.2.1)并不会提取包含目录的提升文件,而它会选择其他目录。这里发生了什么?GCC不使用Boost文件夹包含标志

这是最后的GCC命令正在发出:

gcc -g -stdlib=libstdc++ -Wall -Wno-error -ferror-limit=1000 -fmessage-length=0 
-DHCUBE_NOGUI -DTIXML_USE_STL -DMACOS -mmacosx-version-min=10.5 -arch i386 -arch x86_64 
-I/Applications/Webots6.3.0/include/controller/c 
-I/Users/mtw800/experimentSuite/experiment/../HyperNEAT/tinyxmldll/include 
-I/Users/mtw800/experimentSuite/experiment/../HyperNEAT/NE/HyperNEAT/NEAT/include 
-I/Users/mtw800/experimentSuite/experiment/../HyperNEAT/JGTL/include 
-I/Users/mtw800/experimentSuite/experiment/../HyperNEAT/boost_1_57_0/boost/ -DXML1 
-c ModHyperNEAT/mod_ctrler7.cpp -o controllers/mod_ctrler7_1.o 

错误GCC给我:

In file included from ModHyperNEAT/mod_ctrler7.cpp:30: 
In file included from /Users/mtw800/experimentSuite/experiment/../HyperNEAT/NE/HyperNEAT/NEAT/include/NEAT.h:4: 
In file included from /Users/mtw800/experimentSuite/experiment/../HyperNEAT/NE/HyperNEAT/NEAT/include/NEAT_Globals.h:4: 
/Users/mtw800/experimentSuite/experiment/../HyperNEAT/NE/HyperNEAT/NEAT/include/NEAT_Defines.h:23:10: 
fatal error: 'boost/shared_ptr.hpp' file not found 
#include <boost/shared_ptr.hpp> 
    ^
1 error generated. 
make: *** [experiment-modular] Error 1 

升压包括路径:

-I/Users/mtw800/experimentSuite/experiment/../HyperNEAT/boost_1_57_0/boost/ 

存在并且调用find `pwd` -name shared_ptr.hpp给出以下结果:

MW-020708:boost_1_57_0 mtw800$ pwd 
/Users/mtw800/experimentSuite/HyperNEAT/boost_1_57_0 
MW-020708:boost_1_57_0 mtw800$ find `pwd` -name shared_ptr.hpp 
/Users/mtw800/experimentSuite/HyperNEAT/boost_1_57_0/boost/asio/detail/shared_ptr.hpp 
/Users/mtw800/experimentSuite/HyperNEAT/boost_1_57_0/boost/interprocess/smart_ptr/shared_ptr.hpp 
/Users/mtw800/experimentSuite/HyperNEAT/boost_1_57_0/boost/serialization/shared_ptr.hpp 
/Users/mtw800/experimentSuite/HyperNEAT/boost_1_57_0/boost/shared_ptr.hpp 
/Users/mtw800/experimentSuite/HyperNEAT/boost_1_57_0/boost/smart_ptr/shared_ptr.hpp 
/Users/mtw800/experimentSuite/HyperNEAT/boost_1_57_0/boost/thread/csbl/memory/shared_ptr.hpp 

所以我知道boost包含库在那里,路径是正确的,甚至shared_ptr的头文件在那里。为什么GCC没有选择我的包含文件夹路径?

我已经测试了其他包含路径被拾取(因为他们应该)通过删除所有-I标志并重新添加它们当GCC发出错误,它找不到它们。

好奇的是,如果我用home-brew安装boost,并且进一步改变什么,那么我的编译脚本就会“有效”,因为自制软件可能会将提升链接到默认情况下由GCC搜索的目录。不过,这很好,我不希望GCC使用自制软件,因为它必须在不使用自制软件的系统上编译。我该怎么办?为什么GCC只会排除一个包含文件夹而不是所有其他文件夹?这里有什么样的非确定性编译器automagick?

我使用的是OSX Yosemite 10.10,上面提到了Xcode开发者工具。另一台计算机使用相同的OSX和相同的GCC(相同的Xcode开发工具)。

+0

您是否尝试从'-I/Users/mtw800 /.../ HyperNEAT/boost_1_57_0/boost /'中删除最后一个路径元素('boost')? – trojanfoe 2015-04-02 14:15:48

+0

你在开玩笑吗,这似乎是罪魁祸首!如果您将其粘贴为答案,我会稍后接受它作为答案! – 2015-04-02 14:19:44

您需要从删除的最后一个元素(boost):

-I/Users/mtw800/experimentSuite/experiment/../HyperNEAT/boost_1_57_0/boost/ 

源文件中使用#include <boost/whatever.h>,预处理器期望找到boost子目录时,它会搜索包含目录。