gcc当前目录是否为默认静态库,动态库和标头搜索路径? [英] Is the current directory default static library, dynamic library, and header search paths for gcc?

查看:128
本文介绍了gcc当前目录是否为默认静态库,动态库和标头搜索路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GCC简介有一个示例:

Introduction to GCC has an example:

$ gcc -Wall -L. main.c -lhello -o hello 

需要选项"-L."才能将当前目录添加到库搜索路径.

The option ‘-L.’ is needed to add the current directory to the library search path.

这是否意味着当前目录不是静态库文件的默认搜索路径,因此需要通过-L.添加到库搜索路径中吗?

Does it mean that the current directory is not a default search path for static library files, so needs to be added to the library search path by -L.?

动态库文件搜索类似的问题.当前目录是动态库文件的默认搜索路径,还是我们需要通过--rpath .将当前目录添加到动态库搜索路径?

Similar question for dynamic library file search. Is the current directory is a default search path for dynamic library files, or do we need to add the current directory to the dynamic library search paths by --rpath .?

头文件搜索类似的问题.当前目录是头文件的默认搜索路径,还是我们需要通过-I.将当前目录添加到头文件搜索路径? 以下示例是否暗示当前目录是头文件的默认搜索路径,并且我们不需要通过-I.将当前目录添加到头文件搜索路径?

Similar question for header file search. Is the current directory is a default search path for header files , or do we need to add the current directory to the header search paths by -I.? Does the following example imply that the current directory is a default search path for header files , and we don't need to add the current directory to the header search paths by -I.?

$ ls main.c hello.h
hello.h  main.c

$ cat main.c
#include "hello.h"
int
main (void)
{
  hello ("world");
  return 0;
}

$ gcc -c main.c
$

推荐答案

当前工作目录不属于编译器默认库或标头搜索路径的一部分.

The current working directory is not part of the compiler's default library or header search paths.

但是,形式为#include "file"的包含(带引号)将始终搜索当前工作目录,而不管其是否位于标题搜索路径上.因此,只有在使用#include <file>将文件包含在项目目录中时,才需要-I.(您实际上不应该这样做,因为它会使尝试读取您的代码的人迷惑).

However, includes of the form #include "file" (with quotation marks) will always search the current working directory, regardless of whether it is on the header search path or not. As such, -I. is only necessary if you are including files in the project directory using #include <file> (which you really shouldn't do, because it'll confuse anyone trying to read your code).

这篇关于gcc当前目录是否为默认静态库,动态库和标头搜索路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆