1

I've been messing around with some source files (coreutils package source for example), adding to them asynchronous I/O functionality. Now I want to compile, but I need to add -lrt flag to gcc.

What I did is shoving it somewhere to the Makefile file. It once took me an hour to find where to put it so it will work.

I wonder, is there a way to add it during the ./configure phase, so the Makefile will be created automatically and things will just compile with the -lrt flag?

I've tried configuring the additional flag with:

./configure CFLAGS='-g -O2 -lrt'

and indeed I see a change in the Makefile, but it still doesn't work.

Using

make V=1

I see that make executes:

gcc -std=gnu99   -g -O2 -lrt -Wl,--as-needed  -o src/wc src/wc.o src/libver.a lib/libcoreutils.a  lib/libcoreutils.a

notice that -lrt is somewhere in the middle, so for some reason it doesn't work. But if this get executed:

gcc -std=gnu99   -g -O2 -Wl,--as-needed  -o src/wc src/wc.o src/libver.a lib/libcoreutils.a  lib/libcoreutils.a -lrt

it works. Notice that -lrt is at the end.

How can I append a flag to the end automatically through ./configure? or is there some other way to do that?

Partial Solution: After running ./configure, I've edited the Makefile and added -lrt to the LDADD variable - that done the trick.

Gilsho
  • 63
  • 7
  • 1
    http://stackoverflow.com/a/23407800/539465 – Valentin Lorentz Dec 09 '15 at 16:46
  • Possible duplicate of [Append compile flags to CFLAGS and CXXFLAGS while configuration/make](http://stackoverflow.com/questions/23407635/append-compile-flags-to-cflags-and-cxxflags-while-configuration-make) – shellter Dec 09 '15 at 16:50
  • Thank you for the quick reply, but overriding CFLAGS doesn't work. I've edited my question with further details regarding the CFLAGS. – Gilsho Dec 09 '15 at 17:24
  • 1
    It seems like editing LDADD in Makefile does the trick. I looked for a way ./configure will do that automatically, but I can live with editing the Makefile manually if there is no other solution. – Gilsho Dec 09 '15 at 17:42

0 Answers0