简体   繁体   中英

Is the current directory default static library, dynamic library, and header search paths for gcc?

Introduction to GCC has an example:

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

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

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. ?

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 . ?

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM