Que*_*tin 1 c++ include include-path gcc4.9
注意:这个问题在我编写时就已经解决了.我无法找到有关此问题的信息,所以我觉得无论如何发布它都会很有用.建议欢迎.
大家好.我最近在我的Linux Mint上安装了GCC 4.9.1,一直在编译我的一些项目,一切都进展顺利.
现在我想再次开始研究一个这样的项目,从一些源文件排序开始.所以我创建了一个新文件夹并在里面移动了几个.h和.tpp文件.结构如下所示:
.
??? clip
? ??? Clip.h
? ??? ClipImpl.tpp
? ??? Mask.h
:
??? main.cpp
:
??? vect.cpp
??? vect.h
:
Run Code Online (Sandbox Code Playgroud)
main.cpp只是#include "clip/Clip.h",稍后将包含一些用于测试目的的模板实例.clip/Clip.h包括clip/Mask.h,哪些需要vect.h.
注意后者包括不满意,所以编译器正确地抱怨.现在,我希望我#include的所有s都与项目的根目录相关,而不是它们的文件.好吧,我编辑我的Makefile:
# Retrieve the root directory
WD = $(shell pwd)
...
# Add it to the include search paths
%.o: %.cpp # vvvvvvv
$(CXX) $(CXXFLAGS) -I$(WD) -c $<
Run Code Online (Sandbox Code Playgroud)
然后......轰!
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)...),
^
Run Code Online (Sandbox Code Playgroud)
我搜索了一下,实际上发现了写这句话的时候发生了什么.
我实际上time.h在项目的根目录中有一个文件.虽然它到目前为止没有引起任何问题,但它开始被包含在标准标题的位置<time.h>.如果没有重命名文件,我会深入研究GCC文档,找到问题的原因(强调我的):
-I目录
添加目录dir到头部被搜索头文件的目录列表中.这可用于覆盖系统头文件,[...]目录按从左到右的顺序扫描; 标准系统目录之后.
因此,-I选项通过在列表前面浏览目录来覆盖系统头.不好,我想把它放在后面......但下面是解决方案:
-iquotedir
将目录dir添加到要搜索头文件的目录列表的头部,仅用于'#include "file"'; 他们没有被搜索'#include <file>',否则就像-I.
哦.这正是我所需要的.遗憾的是我以前从未听说过这个选项,并且一直在使用-I用于错误的目的.那好吧.案件解决了!
| 归档时间: |
|
| 查看次数: |
209 次 |
| 最近记录: |