views:

28

answers:

1

Hi,

I'm trying to develop a program that uses another internal library done in the same project.

I want to link both. The lib is stored and succesfully compiled under ./lib/mylib and a mylib.a is created. The issue is that I need to include ./lib/mylib directory in the INCLUDE search and also link the program against the library.

Are there any automatically defined variables or do I have to do it by my own like in the Makefile.am below?

SUBDIRS = lib .

# set the include path found by configure
INCLUDES = $(all_includes) -Ilib/mylib

bin_PROGRAMS = myprogram

myprogram_SOURCES = main.c 
myprogram_CPPFLAGS =  $(libmylib_CFLAGS) $(AM_CFLAGS) $(CFLAGS)
nfc_network_config_LDADD =$(LIB_MYLIB)
A: 

Your Makefile could look something like this.

SUBDIRS = lib .
bin_PROGRAMS = myprogram
myprogram_SOURCES = main.c
myprogram_CPPFLAGS = -Ilib/mylib $(AM_CPPFLAGS) 
myprogram_LDADD = lib/mylib/mylib.a

Note that *_CPPFLAGS should usually not be mixed with *_CFLAGS, and that the $(CFLAGS) and $(CPPFLAGS) variables are always used (they are user variables) so you should not have to mention them. Also INCLUDES is an obsolete variable (you should use *_CPPFLAGS instead), and automake will warn about it if you run it with the -Wall option.

adl
but AM_CPPFLAGS is not compatible if you use AM_PROG_CC_C_O. Or is it deprecated?
jlanza
Why do you mean with not compatible? I use subdir-objects and AM_CPPFLAGS in all my projects.
adl

related questions