Take the 2-minute tour ×

Is it possible to specify include paths for C and C++ in a pkg-config file (mylib.pc.in)?

I know I have Cflags field where I can pass any compiler flags, but it is generic and autoconf resolves it by placing all my options, as long as the include paths in X_CFLAGS but not X_CXXFLAGS.

So if I have a project that contains both C and C++ files and specify in Makefile.am:

mybin_CFLAGS     = $(X_CFLAGS)

My C++ files can't see the include path! In the example bellow, mylib.pc.in contains Cflags: -I/my/iclude/path/.

Output compiling a C file:

libtool: compile:  ppc-linux-gcc -DHAVE_CONFIG_H -I. -I./include -I/opt/ELDK/ppc_8xx/usr/include/ -I/my/iclude/path/ -Wall -std=gnu99 -MT libAW3C_IDU_la-aw3c_utility.lo -MD -MP -MF .deps/libAW3C_IDU_la-aw3c_utility.Tpo -c src/aw3c_utility.c  -fPIC -DPIC -o .libs/libAW3C_IDU_la-aw3c_utility.o

Output compiling a C++ file (notice the missing -I/my/iclude/path/):

libtool: compile:  ppc-linux-g++ -DHAVE_CONFIG_H -I. -I./include -I/opt/ELDK/ppc_8xx/usr/include/ -Wall -MT libAW3C_IDU_la-aw3c_stream.lo -MD -MP -MF .deps/libAW3C_IDU_la-aw3c_stream.Tpo -c src/aw3c_stream.cpp  -fPIC -DPIC -o .libs/libAW3C_IDU_la-aw3c_stream.o

Any help will be appreciated. Thanks!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

pkg-config has the option --cflags-only-I that only yields the include paths in Cflags. So you can add something like:

X_INCFLAGS=`pkg-config mylib --cflags-only-I`

to configure.ac. Q: Are you using the PKG_CHECK_MODULES macro in configure.ac?

share|improve this answer
Yes, I am using PKG_CHECK_MODULES. Does it give me anything plus (or less)? Thanks! –  fljx Jul 6 '12 at 16:15
add comment

Your Answer


