0

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 :

make -C pkg-config --cflags --libs jansson src
make: invalid option -- '/' make: invalid option -- 'u' make: invalid option -- '/' Usage: make [options] [target] ...

Phil
  • 305
  • 1
  • 3
  • 13
  • 2
    That isn't how you're supposed to use `pkg-config`, like you say yourself it needs to be added when invoking the compiler, not make. Please add your makefile to provide a [mcve] – user657267 Nov 19 '17 at 17:33
  • 1
    still new to makefile, I thought gcc was incoked with make, I just posted the Makefile – Phil Nov 19 '17 at 18:16
  • In general, you can't do something with Make unless you know how to do it *without* Make. It looks as if the correct compiler command is "cc -o prog prog.c `pkg-config --cflags --libs jansson`", but you must confirm this before you try to build a makefile around it. – Beta Nov 20 '17 at 01:58
  • https://stackoverflow.com/a/20146082/841108 is an answer to a very similar question – Basile Starynkevitch Nov 20 '17 at 13:27

1 Answers1

1

Inside your Makefile do something like this:

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:

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.

Oo.oO
  • 12,464
  • 3
  • 23
  • 45