Re: [Anjuta-list] multiple-target builing order in anjuta 2.0



Hi,

Answering to my own question, the problem is that I made
a mistake: -lfoo should go in "Libraries" field and not in "Linker
Flags" of "Target Properties" dialog.  Just as clue for others
browsing the list archives with similar problems, the rationale
is as follows.

In the example project, $(top_srcdir)/src/foobar is the main binary and
$(top_srcdir)/foo/libfoo.a is a static library that shall be linked to
foobar.
I need the library to be build before the binary, so my toplevel
Makefile.am lists SUBDIRS = foo src. 

I then run configure="LDFLAGS="-L$(top_srcdir)/foo" so that the
linker can find libfoo.a in $(top_srcdir)/foo (just for the case there
is already a system-installed libfoo.a in /usr/lib, for example).

If I specify -lfoo as a "Linker Flag", it will generate 
foobar_LDFLAGS = -lfoo in src/Makefile.am, which will
result in the following gcc invocation during linking time:

gcc -Wall -g -g -O2  -L../foo -o foobar -lfoo  main.o

Notice that the linker scans  libfoo.a before main.o, so it
does not know what symbols to find, and the buld fails.

Nos, if I put -lfoo in Libraries field of Properties dialog,
it will generate foobar_LDADD in src/Makefile.am, which will
result in

gcc -Wall -g -g -O2  -L../foo -o foobar  main.o -lfoo

with the linker scanning libfoo.a after processing main.o

Usualluy, foobar_LDADD addes it's arguments as
foobar_DEPENDENCIES, but it's smart enought to
exclude those staring with |-l|, |-L|, |-dlopen| and |-dlpreopen
(see auomake documentation).

|Thanks.
monaco


> For that to work, -lfoo would have to appear after main.o;
> the way it is, instead, -lfoo causes the linker to scan for the
> library before the binary where the symbols are referenced,
> so it does not look for the simble foo.
>
> I have entered '-lfoo'  for the Library Flags field in the foobar's
> Target Proprieties diolog.  How to force it be used by the
> end of the line? Or after the target?
>
>
> make[2]: Leaving directory `/home/monaco/Projects/foobar/foo'
> Making all in src
> make[2]: Entering directory `/home/monaco/Projects/foobar/src'
> gcc -Wall -g -g -O2  -L../foo -o foobar -lfoo  main.o
> main.o: In function `main':
> /home/monaco/Projects/foobar/src/main.c:32: undefined reference to `foo'
> collect2: ld returned 1 exit status
>
>   





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]