Question

I am new to automake tools. In "src/Makefile.am", I use "AM_LDFLAGS = -L... -l...".

Then, I run "autoreconf --force --install ; ./configure ; make"

In the last command,

$ g++ -O2 -L... -l... -o target_name [some *.o files]

the compiler complains "undefined reference to ...".

But if I copy it and move "-L... -l..." to the end, and run it independently it is fine (below).

$ g++ -O2 -o target_name [some *.o files] -L... -l...

So the order of options does matter? Anyway, how to smooth it?

Thanks a lot.

Était-ce utile?

La solution

For the "-L" options, try using the LDADD or target_name_LDADD variable instead (where target_name is replaced with the actual target name). This places these flags at the end of the linking command.

The order of "-l" and "-L" does make a difference. From http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html:

-l library Search the library named library when linking. ... It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded. ... The linker handles an archive file by scanning through it for members which define symbols that have so far been referenced but not defined.

So libraries should appear after object files/other libraries that depend upon them.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top