C语言 如何在单个 gcc 命令中将多个头文件包含和库目录添加到搜索路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5846804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 08:32:49  来源:igfitidea点击:

How to add multiple header include and library directories to the search path in a single gcc command?

cgcc

提问by Bingo

How to add multiple header include and library directories to the search path in a single gcc command?

如何在单个 gcc 命令中将多个头文件包含和库目录添加到搜索路径?

回答by Chris Stratton

Use multiple -I flags for the include directories and multiple -L flags for the lib directories

对包含目录使用多个 -I 标志,对 lib 目录使用多个 -L 标志

回答by Brian Roach

You can set the C_INCLUDE_PATHenvironment variable.

您可以设置C_INCLUDE_PATH环境变量。

export C_INCLUDE_PATH=.:/some/dir:/some/other/dir

as well as the LIBRARY_PATHenvironment variable.

以及LIBRARY_PATH环境变量。

回答by Jeff Pal

On Linux you need to use -Ibefore each directory that you want to add.

在 Linux 上,您需要-I在要添加的每个目录之前使用。

Example:

例子:

user:/home/my_project$ gcc -g -Wall -I/usr/include/lib_Directory/ -I./include -c ./src/transcod.c

./means the current directory where you are running the command, in this case my_project;

./表示您运行命令的当前目录,在本例中为my_project