开发者

How do you set the order of libraries in automake?

开发者 https://www.devze.com 2022-12-10 15:56 出处:网络
How do you set the order of libraries in automake? In my am file I have something like: myprog_DEPENDENCIES = adhoc-target

How do you set the order of libraries in automake?

In my am file I have something like:

myprog_DEPENDENCIES = adhoc-target
myprog_SOURCES = myprog.c
myprog_LDADD = libmine.la
myprog_LDFLAGS = -static -L/home/user/lib -ladhoc

Now, when I compile I get this compile line similar too:

gcc -static myprog-myprog.o -o myprog -L/home/user/lib -ladhoc ./.libs/libmine.a

The problem is that libmine.a depends on libadhoc.a, therefore the compile line should be:

gcc -static myprog-myprog.o -o myprog ./.libs/libmine.a -L/home/user/lib -ladhoc

How do you set the order of libraries in automake? (Or maybe a work around; how do you repeat all the libraries in the compile line. That's what开发者_运维问答 I do in my custom Makefiles.)


From the Automake manual (mostly §8.1.2 but also §8.4):

PROG_LDADD is inappropriate for passing program-specific linker flags (except for -l, -L, -dlopen and -dlpreopen). So, use the PROG_LDFLAGS variable for this purpose.

That implies you can (but actually you should) use -l and -L in LDADD, not in LDFLAGS. In other words your Makefile.am should simply read

myprog_DEPENDENCIES = adhoc-target
myprog_SOURCES = myprog.c
myprog_LDADD = libmine.la -L/home/user/lib -ladhoc
myprog_LDFLAGS = -static 


One idea from the automake book (http://sources.redhat.com/autobook/autobook/autobook_92.html): create a convenience library out of libmine and libadhoc, and link myprog against that.

0

精彩评论

暂无评论...
验证码 换一张
取 消