2014-09-24 93 views
1

注:这个问题在我写它的时候把它排序。我很难找到关于这个问题的信息,所以我觉得无论如何发布信息都是有用的。忠告欢迎。GCC -I打破标准库编译


大家好。我最近在Linux Mint上安装了GCC 4.9.1,已经编译了我的一些项目,并且一切都很顺利。

现在我想重新开始一个这样的项目,从一些源文件排序开始。所以我创建了一个新文件夹,并在里面移动了一对.h和.tpp文件。该结构是这样的:

. 
├── clip 
│   ├── Clip.h 
│   ├── ClipImpl.tpp 
│   └── Mask.h 
: 
├── main.cpp 
: 
├── vect.cpp 
├── vect.h 
: 

main.cpp只是#include "clip/Clip.h",稍后会包含用于测试一些模板实例。 clip/Clip.h包括clip/Mask.h,其需要vect.h

请注意,后者包括不满意,所以编译器正确地抱怨。现在,我希望我所有的#include都是相对于项目的根,而不是它们的文件。好的,我编辑我的Makefile:

# Retrieve the root directory 
WD = $(shell pwd) 

... 

# Add it to the include search paths 
%.o: %.cpp #   vvvvvvv 
    $(CXX) $(CXXFLAGS) -I$(WD) -c $< 

然后......轰隆??

g++ -std=c++1y `sdl2-config --cflags` -Wall -Wextra -Winline -fno-rtti -I/home/quentin/NetBeansProjects/glk -c AutoDisplayed.cpp 
In file included from /home/quentin/NetBeansProjects/glk/time.h:4:0, 
       from /usr/include/sched.h:33, 
       from /usr/include/pthread.h:23, 
       from /opt/gcc-4.9.1/include/c++/4.9.1/x86_64-unknown-linux-gnu/bits/gthr-default.h:35, 
       from /opt/gcc-4.9.1/include/c++/4.9.1/x86_64-unknown-linux-gnu/bits/gthr.h:148, 
       from /opt/gcc-4.9.1/include/c++/4.9.1/ext/atomicity.h:35, 
       from /opt/gcc-4.9.1/include/c++/4.9.1/bits/basic_string.h:39, 
       from /opt/gcc-4.9.1/include/c++/4.9.1/string:52, 
       from /opt/gcc-4.9.1/include/c++/4.9.1/stdexcept:39, 
       from /opt/gcc-4.9.1/include/c++/4.9.1/array:38, 
       from /opt/gcc-4.9.1/include/c++/4.9.1/tuple:39, 
       from /opt/gcc-4.9.1/include/c++/4.9.1/bits/stl_map.h:63, 
       from /opt/gcc-4.9.1/include/c++/4.9.1/map:61, 
       from AutoDisplayed.h:5, 
       from AutoDisplayed.cpp:1: 
/opt/gcc-4.9.1/include/c++/4.9.1/functional: In member function ‘_Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...)’: 
/opt/gcc-4.9.1/include/c++/4.9.1/functional:1322:8: error: ‘forward_as_tuple’ is not a member of ‘std’ 
     std::forward_as_tuple(std::forward<_Args>(__args)...), 
     ^

我已经搜索了一个好位,并且实际上发现了写这句话时发生了什么。

回答

5

我的项目的根目录中实际上有一个time.h文件。尽管到目前为止它没有引起任何问题,但它开始包含在标准标题<time.h>的位置。短重命名文件的,我挖成GCC文档,发现问题(重点煤矿)的原因:

-I DIR
添加目录dir到的目录列表的头部搜索头文件。这可用于覆盖系统 头文件,目录以 从左到右顺序扫描; 标准系统目录在之后。

所以,-I选项覆盖系统头在列表中的前plonking目录。不行,我想有它在后面......但略低于方案如下:

-iquote DIR
目录dir添加到目录列表的头部以搜索头文件仅用于'#include "file"'的情况;他们 不搜索'#include <file>',否则就像-I。

哦。这正是我需要的。我以前从来没有听说过这种选择是一种耻辱,并一直在使用-I出于错误的目的。好吧。案件解决了!