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.