2014-09-24 87 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出於錯誤的目的。好吧。案件解決了!