开发者

How to link a non-standard header file into a C compiler

开发者 https://www.devze.com 2023-01-28 00:55 出处:网络
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 ob

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. Cheers.


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:

#include <include_file.h>

and

#include "include_file.h"

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.

gcc -I/usr/local/gnuplot/inc -L/usr/local/gnuplot/lib -lgnuplot -o my_prog my_prog.c


Most compilers have a flag -I that lets you add a directory of your choosing to the search path for include files.

0

精彩评论

暂无评论...
验证码 换一张
取 消