提问者:小点点

如何编译包含外部库头的C++程序?


我正在尝试编译一个包含外部库头的。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++非常熟悉。


共1个答案

匿名用户

指令#包括和选项-i thelibdir尝试查找名为root/thelibdir/thelibdir/lib_header1.h的文件。

两种解决方案:使用指令#include或将目录放在编译选项-i中。

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(编译|包含|外部|库|头|c++|程序)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?