如何将非标准头文件链接到 C 编译器中
我正在尝试使用非标准头文件(http://ndevilla.free.fr/gnuplot)。它在我计算机上不同地方的许多代码中使用。目前,我必须将头文件和目标文件放入预处理器指令所需的每个文件夹中:
#include "gnuplot_i.h"
在文件中。有没有一种方法可以将头文件放在一个地方,以便我可以像其他标准头文件一样引用它?
I'm trying to use a non-standard header file (http://ndevilla.free.fr/gnuplot). Its used in lots of codes in various different places on my computer. Currently I have to put the header file and the object file in every folder which its needed with the preprocessor directive:
#include "gnuplot_i.h"
In the file. Is there a way by which I can put the header file in one place so I can reference it like other standard header file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
-I
进行编译 例如使用
-I/usr/local/gnuplot/inc
进行编译。此外,可能值得您阅读包含路径以及以下内容之间的区别:
和
目标文件中的链接需要以与 C 文件相同的方式显式完成,这意味着(我相信)您需要完整路径。但是,如果您将其存档到正确的库中,则可以使用
-l
和-L
代替。例如Compile with
-I<directory>
E.g.
compile with
-I/usr/local/gnuplot/inc
.Also it might be worth your reading up on include paths and the difference between:
and
Linking in an object file needs to be done explicitly the same way as a C file, which means (I believe) that you need a full path. However if you archive it into a proper library then you can use
-l<library name>
and-L<library path>
instead. E.g.大多数编译器都有一个标志
-I
,可让您将选择的目录添加到包含文件的搜索路径中。Most compilers have a flag
-I
that lets you add a directory of your choosing to the search path for include files.