我正试图编译一个.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路径不包含LibDir中的./lib_header{2|3}.h
或src目录中的../theLibDir/lib_header1.
。然后,关于编译,到目前为止,我尝试(从ROOT
目录(:
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++非常熟悉。
指令#include <theLibDir/lib_header1.h>
和选项-I theLibDir
尝试查找名为ROOT/theLibDir/theLibDir/lib_header1.h
的文件。
两种解决方案:使用指令#include <lib_header1.h>
或将ROOT
目录放在编译选项-I
中。