1

Note: This question sorted itself out while I was writing it. I had trouble finding information on this problem, so I feel it would be useful to post it anyway. Advice welcome.


Hello everyone. I've recently installed GCC 4.9.1 on my Linux Mint, have been compiling some projects of mine, and everything has gone smoothly.

Now I want to get working on one such project again, beginning with some source files sorting. So I created a new folder and moved a couple .h and .tpp files inside. The structure looks like this :

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

main.cpp is just #include "clip/Clip.h", and will later contain some template instantiations for testing purposes. clip/Clip.h includes clip/Mask.h, which needs vect.h.

Note that the latter include is not satisfied, so the compiler rightly complains. Now, I would like all my #includes to be relative to the project's root, and not the file they are made from. Alright, I edit my Makefile :

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

...

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

And then... Boom ??

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)...),
        ^

I've searched for a good bit, and actually found out what was going on while writing this very sentence.

4

1 回答 1

5

我实际上time.h在我的项目的根目录中有一个文件。虽然到目前为止它没有引起任何问题,但它开始被包含在标准 header 的位置<time.h>。没有重命名文件,我深入研究了 GCC 文档并找到了问题的原因(强调我的):

-Idir
将目录 dir 添加到要搜索头文件的目录列表的头部这可用于覆盖系统头文件,[...] 目录按从左到右的顺序扫描;标准系统目录紧随其后

因此, -I 选项通过将您的目录放在列表前面来覆盖系统标题。不好,我想把它放在后面......但下面是解决方案:

-iquotedir
仅针对'<code>#include "file"'的情况将目录dir添加到要搜索头文件的目录列表的头部;他们不会搜索'<code>#include <file>',否则就像-I。

哦。这正是我所需要的。很遗憾我以前从未听说过该选项,并且一直将 -I 用于错误的目的。那好吧。案件破案!

于 2014-09-24T08:04:58.143 回答