问题描述
当我编译包含预编译头的c ++文件时,一切正常工作。
// test.c ++
#include< precompiled.h>
#include< header.h>
main(){}
> g ++ - 4.7 --std = c ++ 11 BLAH ... test.c ++ -H 2>& 1 | grep precompiled.h
! precompiled.h.gch
(!表示gcc找到并使用了预编译头)
但是,当我把#include< precompiled.h> into header.h,它不工作:
// test.c ++
#include < header.h>
main(){}
> g ++ - 4.7 --std = c ++ 11 BLAH ... test.c ++ -H 2>& 1 | grep precompiled.h
。 precompiled.h
(无!或x表示gcc无法找到预编译头)
发生了什么事?我的理解是,只要gcc命中一个#include指向一个相应的.gch的头,在任何C / C ++令牌之前,它将使用GCH,这暗示一个子包含应该是好的。 p>
我错了吗?
文档。 Gcc不再支持子包中的预编译头:
错误归档:
When I compile a c++ file that includes a precompiled header, everything works as expected
// test.c++
#include <precompiled.h>
#include <header.h>
main() {}
> g++-4.7 --std=c++11 BLAH... test.c++ -H 2>&1 | grep precompiled.h
! precompiled.h.gch
(! means that gcc found and used the precompiled header)
However, when I put #include < precompiled.h > into header.h, it doesn't work:
// test.c++
#include <header.h>
main() {}
> g++-4.7 --std=c++11 BLAH... test.c++ -H 2>&1 | grep precompiled.h
. precompiled.h
(no ! or x means that gcc failed to find the precompiled header)
What's going on? My understanding was that as long as gcc hit an #include that pointed to a header with a corresponding .gch before any C/C++ tokens, it would use the GCH, which suggests to me that a sub-include should be okay.
Am I mistaken?
This turned out to be a bug in the documentation. Gcc no longer supports precompiled headers in subincludes:
Bug filed: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52518
这篇关于在GCC中,可以从其他头文件包含预编译头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!