【问题标题】:GCC -I breaks standard library compilationGCC -I 破坏标准库编译
【发布时间】:2014-09-24 08:04:58
【问题描述】:

注意:这个问题是在我写它的时候自行解决的。我很难找到关于这个问题的信息,所以我觉得无论如何发布它会很有用。欢迎咨询。


大家好。我最近在我的 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

请注意,后者包含不满足,因此编译器正确地抱怨。现在,我希望我的所有#includes 都相对于项目的根目录,而不是它们所来自的文件。好的,我编辑我的 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)...),
        ^

我已经搜索了很多,实际上在写这句话时发现了发生了什么。

【问题讨论】:

    标签: c++ include include-path gcc4.9


    【解决方案1】:

    我的项目根目录中实际上有一个time.h 文件。虽然到目前为止它没有引起任何问题,但它开始取代标准标题&lt;time.h&gt;。没有重命名文件,我深入研究了 GCC 文档并找到了问题的原因(强调我的):

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

    所以,-I 选项覆盖系统头文件,把你的目录放在列表前面。不好,我想把它放在后面...但是下面是解决方案:

    -iquote目录
    仅针对‘#include "file"’的情况,将目录dir添加到要查找头文件的目录列表的头部;他们 不搜索'#include &lt;file&gt;',否则就像-I。

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

    【讨论】:

      猜你喜欢
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 2011-06-10
      • 1970-01-01
      • 2019-10-29
      • 2018-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多