當我read該編譯器錯誤使用的#include「文件名」
#include filename
使由「分隔符之間的指定序列所標識的源文件的全部內容替換該指令的。
簡單例子如下。與g++ main.cpp f.h f.cpp
編譯會產生編譯錯誤。該程序運行正常後,我刪除f.cpp
的#include
。我有兩個問題。
原始程序中的錯誤原因是什麼?
#include filename
是否真的只是用引用文件的內容替換指令?
請問第二個問題,因爲該程序也可以正常運行,當我替換int f();
問題的行(這是f.h
的確切內容)。
謝謝。
f.h
int f();
f.cpp
#include "f.h" // problem
int f() { return 1; }
的main.cpp
#include <iostream>
#include "f.h"
int main() {
std::cout << f() << std::endl;
}
與原來的程序運行g++ main.cpp f.h f.cpp
的錯誤消息是
f.cpp: In function 'int f()':
f.cpp:2:5: internal compiler error: in ggc_record_overhead, at ggc-common.c:1013
int f() { return 1; }
^
0x8ae8eb ggc_record_overhead(unsigned long, unsigned long, void*, char const*, int, char const*)
/apps2/tools/gcc/4.9.2/gcc-4.9.2-src/gcc/ggc-common.c:1013
0xc4af71 ggc_internal_alloc_stat(unsigned long, char const*, int, char const*)
/apps2/tools/gcc/4.9.2/gcc-4.9.2-src/gcc/ggc-page.c:1317
0xa48462 get_combined_adhoc_loc(line_maps*, unsigned int, void*)
/apps2/tools/gcc/4.9.2/gcc-4.9.2-src/libcpp/line-map.c:136
0xa9a5ff gimple_set_block(gimple_statement_base*, tree_node*) [clone .isra.8]
/apps2/tools/gcc/4.9.2/gcc-4.9.2-src/gcc/gimple.h:1489
0xa9a5ff lower_stmt
/apps2/tools/gcc/4.9.2/gcc-4.9.2-src/gcc/gimple-low.c:239
0xa9a5ff lower_sequence
/apps2/tools/gcc/4.9.2/gcc-4.9.2-src/gcc/gimple-low.c:206
0xa9b481 lower_gimple_bind
/apps2/tools/gcc/4.9.2/gcc-4.9.2-src/gcc/gimple-low.c:415
0xa9b5c6 lower_function_body
/apps2/tools/gcc/4.9.2/gcc-4.9.2-src/gcc/gimple-low.c:118
0xa9b5c6 (anonymous namespace)::pass_lower_cf::execute() [clone .lto_priv.4979]
/apps2/tools/gcc/4.9.2/gcc-4.9.2-src/gcc/gimple-low.c:184
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
UPDATE:
我發現g++ main.cpp f.cpp f.h
失敗,因爲在我的目錄中的文件f.h.gch
。該程序編譯後,我清理.gch
文件。
(我很抱歉,我沒有按照我只注意到它之前此信息。)
然而,g++ main.cpp f.cpp f.h
產生f.h.gch
。所以如果我連續編譯兩次,這將是一個錯誤。
按照Donghui的建議,從g++
刪除f.h
也編譯正確。而且,它不生成f.h.gch
文件。
我的問題是有可能的What is a .h.gch file?
是的,#include filename用引用文件的內容替換指令。你顯示的代碼應該可以工作。其他的東西(你沒有顯示)導致了「問題」。請告訴我們更多。特別是,你是如何編譯的?錯誤信息是什麼? –
「原始程序中出現錯誤的原因是什麼?」錯誤消息告訴你什麼? – juanchopanza
@DonghuiZhang謝謝。我現在已經包含錯誤消息。它說「內部編譯器錯誤」,我不太明白。 – sam