How to change the default-search-path values for GNU GCC for regular usage?

只愿长相守 提交于 2021-01-28 11:41:41

问题


GNU GCC Compiler Environment Variables Default-Search-Path — I am trying to change default values of GCC environment variables to new custom values so that the default search path will contain any needed additional libraries or include header files that I would like to use on a regular basis.

My version of GNU GCC is: gcc (MinGW.org GCC Build-2) 9.2.0

Include directories for .h header files for this <…> not "…" which would be in the same directory as .c file extension.

Include Header Directories:

  1. CPATH
  2. C_INCLUDE_PATH
  3. CPLUS_INCLUDE_PATH
  4. OBJC_INCLUDE_PATH

Library File Directories:

  1. LIBRARY_PATH

I realized that these are Windows Environment Variables.
And That I could Simply just create Windows User Environment Variables.

Here is a command which will show default search paths for GNU GCC Compiler.

cpp -v

This shows include directory default search path.

gcc -print-search-dirs

This shows library directory default search path.

This Command Prompt Command tells me the default-search-paths which are set during installation of GNU GCC Compiler I assume these are considered Environment Variables and I am looking to see if anyone on the web could give me any urls in regards to changing this default search path value.

Here are a few links related to what I am doing. I used that information although I was still unable to accomplish what I was intending to accomplish.

  • GCC environment variables
  • C Preprocessor search path
  • C preprocessor environment variables
  • GCC configuration

回答1:


Recent GCC compilers have some (optional) .spec files.

You could edit yours, and that file drives the actual compilation processes. As you know, gcc is mostly starting some cc1 / cc1plus internal program (then ld)

But I recommend to not edit your .spec file.

Instead of that, configure your build procedure, e.g. edit your Makefile for GNU make or your build.ninja file (actually, the generator of that file) for ninja builder.

Of course, read the chapter about Invoking GCC.

BTW, GNU make has a lot of built-in rules. Use make -p to understand them.

You could also take inspiration from GNU autoconf.

You could also code your own GCC plugin, implementing your own #pragma which would customize the behavior of gcc. I am not sure it is a good idea.

How to change the default-search-path values?

don't do that, learn to use GCC instead

You might want, from time to time, to compile your code with Clang, to check that your code base is not tied to one particular compiler.

You could use Frama-C or the Clang static analyzer on your C code. In some cases, some bugs could be found at compile time. You certainly want to pass explicitly both -Wall and -Wextra to gcc (and notice that clang accepts them also)

PS. This is from a GNU/Linux perspective. Adapt that to your proprietary operating system. Or consider getting the permission to switch to Linux (see also this draft report funded by the CHARIOT European project).



来源:https://stackoverflow.com/questions/65272498/how-to-change-the-default-search-path-values-for-gnu-gcc-for-regular-usage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!