C语言中include指令的区别
在进行C语言编程是常常需要使用include指令引入已有的头文件,以便重用已有的函数。include有两种形式,一种使用#include <file>,一种使用#include "file",两种的区别在于查找的目录不一样。
-
#include <file>
在预定义的系统目录中查找文件。
-
#include “file”
首先在当前文件的目录查找,然后在预定义的系统目录中查找文件。
预定义的系统目录可以通过命令cpp -v /dev/null -o /dev/null查看。例如:
$ cpp -v /dev/null -o /dev/null
··········
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks (framework directory)
············
相关问题
使用CLion进行编译时,CMake报错
fatal error: ‘stdio.h’ file not found
编辑项目下面的CMakeLists.txt文件,在文件中增加头文件目录即可,目录的查找方式参见上面的指令
include_directories(path/to/the/file)