If this article helps you, feel free to follow Programmer Xiao Mi . Wishing you progress in your programming journey!
Different paths may contain the same header files, and the search rules for header files also have their own regulations. Library files similarly have search path issues.
GCC Header Files
When compiling C code with GCC, the search order for header files differs based on whether they are specified with “” or <>.
-
“”
-
The current directory of the source code file being compiled
-
-iquote specified paths (only for header files enclosed in quotes; if multiple paths, they are searched from left to right)
-
-I specified paths (if multiple paths, they are searched from left to right)
-
-isystem specified paths (if multiple paths, they are searched from left to right)
-
Standard system header file paths
-
-idirafter specified paths (if multiple paths, they are searched from left to right)
-
<>
-
-I specified paths (if multiple paths, they are searched from left to right)
-
-isystem specified paths (if multiple paths, they are searched from left to right)
-
Standard system header file paths
-
-idirafter specified paths (if multiple paths, they are searched from left to right)
If interested, you can create multiple header files with the same name in different paths and test the above order using “” or <> to validate one by one. Interestingly, even the system header file <stdio.h> can be changed to “stdio.h”, thus following the search order for “” and effectively overriding the system header file.
MSVC Header Files
-
“”
-
Directory of the source code
-
/I specified paths
-
Standard system header file paths
-
<>
-
/I specified paths
-
Standard system header file paths
GCC Library Files
Library files do not have as many classifications as header files:
-
-L parameter
-
LIBRARY_PATH or LD_LIBRARY_PATH
-
/etc/ld.so.conf paths
-
System default library paths (e.g., /lib, /usr/lib, etc.).
If this article helps you, feel free to follow Programmer Xiao Mi . Wishing you progress in your programming journey!
The breeze is gentle, the sun is just right, you pass by like the wind here, may your stay be warm and comfortable.
I am Programmer Xiao Mi (dedicated to sharing tips and experiences in programming technologies such as C, C++, C#, Android, iOS, Java, Kotlin, Objective-C, Swift, Shell, JavaScript, TypeScript, Python, etc.), if my work helps you, please follow, share, like, bookmark, and interact. Your support is our greatest motivation to assist you. If you want to receive updates regularly, please leave comments, click “view” or set our WeChat public account as a star.
1. If you want to learn more, you can follow the WeChat public account:Programmer Xiao Mi (a public account focused on software development skills and experiences)
miniminicode
or scan the code:
2. You can also visit the website Mi Soft Technology:https://www.minicoda.com
or scan the code: