我正在尝试编译一个包含外部库头的。cpp文件,而该头包含来自所述库的其他头。 目录结构如下:
ROOT/
├── theLibDir/
│ ├── lib_header1.h # includes "theLibDir/lib_header2.h" and "theLibDir/lib_header3.h"
│ ├── lib_header2.h
│ ├── lib_header3.h
├── src/
│ ├── noob.cpp # includes "theLibDir/lib_header1.h"
首先,我不明白为什么include路径不包含theLibDir中的./lib_header{23}.h
或src目录中的../theLibDir/lib_header1.
。 然后,关于编译,到目前为止我尝试了(从根
目录):
gcc -o noob src/noob.cpp
gcc -o noob src/noob.cpp theLibDir/lib_header1.h
gcc -o noob src/noob.cpp -ItheLibDir
gcc -o noob src/noob.cpp -LtheLibDir -llib_header1
我总是得到同样的错误:
src/noob.cpp:39:10
fatal error: 'theLibDir/lib_header1.h' file not found
#include "theLibDir/lib_header1.h"
有谁能指导我这方面的工作吗? 你可能已经知道了,我对C++非常熟悉。
指令#包括
和选项-i thelibdir
尝试查找名为root/thelibdir/thelibdir/lib_header1.h
的文件。
两种解决方案:使用指令#include
或将根
目录放在编译选项-i
中。