MathManiac MathManiac - 1 year ago 98
C++ Question

Autotools adds library flags to ar

I'm currently porting my C++ project to use the GNU autotools toolchain, and I'm having trouble setting up my library dependencies. What seems to be happening is that it gives the command

flags meant for g++, such as
-lSDL2 -L/usr/local/lib -lSDL2_image -lSDL2

Here's the code for

noinst_LIBRARIES = libccade.a
libccade_a_SOURCES = CCade.h CCade_graphics.h CCade_graphics.cpp CCade_util.h CCade_util.cpp
libccade_a_LIBADD = $(libsdl2_LIBS) $(libsdl2_image_LIBS)
libccade_a_CFLAGS = $(libsdl2_CFLAGS) $(libsdl2_image_CFLAGS)

Here's what
puts out:

ar cru libccade.a CCade_graphics.o CCade_util.o -lSDL2 -L/usr/local/lib -lSDL2_image -lSDL2
ar: invalid option -- 'L'
Usage: ar [emulation options] [-]{dmpqrstx}[abcDfilMNoPsSTuvV] [--plugin <name>] [member-name] [count] archive-file file...
...(more documentation on ar)...

It seems to be adding the args from
, but if I remove that variable, then it wouldn't give the flags to
. What do I do?

Answer Source

It looks like you are not using libtool. What I generally do is put this in my


And then my would be something like:

noinst_HEADERS = CCade.h CCade_graphics.h CCade_util.h


libccade_la_SOURCES = CCade_graphics.cpp CCade_util.cpp
libccade_la_LIBADD = $(libsdl2_LIBS) $(libsdl2_image_LIBS)
libccade_la_CPPFLAGS = $(libsdl2_CFLAGS) $(libsdl2_image_CFLAGS)

Making sure that the second variable is noinst_LTLIBRARIES, it should work for you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download