本文介绍了如何让GCC在当前源文件的目录之前搜索目录中的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在使用多架构构建的项目中使用GCC预编译头文件,但是当我试图将其放在与当前源目录不同的目录中时,事情就会崩溃。 该文件包含在双引号中,如果将其更改为尖括号,它会起作用,但问题是我有许多其他项目使用相同的预编译的头名称,所以将它们全部更改为尖括号是不可取的,因为它可能会在Visual Studio构建的相同文件中产生含糊不清的头文件。 GCC在其搜索路径之前搜索当前目录中的双引号。我可以使用 -I - 选项来解决它(例如 -Ipch_dir.i686 -I - ),以便预编译在当前目录之前搜索标题目录,但不推荐使用此选项。 GCC建议我使用 -iquote ,但它与 -I - 不一样。 所以问题是如何在不改变所有预编译头文件include指令的情况下使用尖括号和使用不推荐的GCC开关? 解决方案我已经找到了一个解决方法。 $ b 以不同的名称构建预编译头。例如,头文件是 ah ,原始预编译头文件是 pchdir.i686 / ahgch ,将其编译为 gcc ah -o pchdir.i686 / a-precompiled.h.gch 使用GCC的 -include 开关确保重命名的标题包含在 / em>其他任何东西(甚至在原始 ah 之前),例如 gcc -Ipchdir.i686 -include a-precompiled.h< other arguments> <信源> 源文件中的最终包含顺序为: a- precompiled.h.gch , ah ,我已经检查了 -H 。包含原始头文件,但实际上没有处理,因为预编译头文件具有相同的包含保护符(也可以通过在构建预编译头文件后在原始头文件中插入 #error 来验证)。 I am using GCC precompiled headers in my project with multi-architecture build, but things break down when I try to place it in a directory different from current source's directory.The file is included with double quotes, and it works if I change it to angle brackets, but the problem is that I have a lot of other projects that use the same precompiled header name, so changing all of them to angle brackets is not desirable as it may create ambiguity about which header to include in Visual Studio build of the same files.GCC searches current directory for double-quote includes before its search path. I can work around it using -I- option (e.g. -Ipch_dir.i686 -I-), so that precompiled headers directory is searched before the current directory, but this option is deprecated. GCC suggests I use -iquote, but it does not have the same effect as -I-.So the question is how do I make it work without changing all precompiled headers include directives to angle brackets and using a deprecated GCC switch? 解决方案 I have found a workaround.Build a precompiled header under a different name. For example is the header is a.h, original precompiled header is pchdir.i686/a.h.gch, build it asgcc a.h -o pchdir.i686/a-precompiled.h.gchUse GCC's -include switch to make sure the renamed header is included before anything else (even before the original a.h), e.g.gcc -Ipchdir.i686 -include a-precompiled.h <other arguments> <source>Final inclusion order in the source file will be: a-precompiled.h.gch, a.h, which I've checked with -H. Original header is included, but is not actually processed because precompiled header has identical include guards (verified as well by inserting an #error in the original header after building the precompiled one). 这篇关于如何让GCC在当前源文件的目录之前搜索目录中的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-27 19:01