简体   繁体   English

与库链接的C程序

[英]C programs linked with library

I am trying to link a Library to my C program but I can't make it work according to the library doc https://jansson.readthedocs.io/en/latest/gettingstarted.html#compiling-and-installing-jansson all I have to do is put pkg-config --cflags --libs jansson after GCC in the Makefile, but I get the following error : 我正在尝试将库链接到我的C程序,但是根据库文档https://jansson.readthedocs.io/en/latest/gettingstarted.html#compiling-and-installing-jansson all,我无法使其工作我要做的是在Makefile中的GCC之后放置pkg-config --cflags --libs jansson ,但是出现以下错误:

make -C pkg-config --cflags --libs jansson src 制作-C pkg-config --cflags --libs jansson src
make: invalid option -- '/' make: invalid option -- 'u' make: invalid option -- '/' Usage: make [options] [target] ... make:无效选项-'/'make:无效选项-'u'make:无效选项-'/'用法:make [选项] [目标] ...

Inside your Makefile do something like this: 在您的Makefile中执行以下操作:

LIBS = $(shell pkg-config --libs jansson)
CFLAGS = $(shell pkg-config --cflags jansson)

Then, inside your targets (where you compile/link your code) use it following way: 然后,在目标内部(您在其中编译/链接代码的地方)按以下方式使用它:

cc ... $(LIBS) $(CFLAGS)

If you are looking for Makefile sample, take a look here: 如果您正在寻找Makefile示例,请在此处查看:

http://www.owsiak.org/fortran-and-gnu-make/ http://www.owsiak.org/fortran-and-gnu-make/

It is not exactly what you are looking for, but it should give you some ideas about Makefile structure, targets, wildcards, etc. It's Fortran based, but I am pretty sure you can easily read it. 它并不是您真正想要的,但是它应该给您一些关于Makefile结构,目标,通配符等的想法。它基于Fortran ,但是我敢肯定您可以轻松阅读它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM