Ubuntu LDFLAGS --as-needed
===

I have a C project that won't link correctly, and I suspect it's because of the --as-needed flag passed to the ld program by gcc.  Because of that flag, gcc sees any linked library listed as an option before the *.c files as unnecessary, and won't link them.  

<pre><code>
PREFIX?=/usr/local
CFLAGS=-D_LARGEFILE64_SOURCE=1 -g -Wall -I${PREFIX}/apr/include/apr-1  -I${PREFIX}/apr/include/apr-util-1
LDFLAGS=-lapr-1 -pthread -laprutil-1

all: devpkg
devpkg: bstrlib.o db.o shell.o commands.o 
install: all
	install -d $(DESTDIR)/$(PREFIX)/bin/
	install devpkg $(DESTDIR)/$(PREFIX)/bin/

clean:
	rm -f *.o
	rm -f devpkg
	rm -rf *.dSYM
</code></pre>

When I run this makefile I get the following.

<pre><code>
cc -D_LARGEFILE64_SOURCE=1 -g -Wall -I/usr/local/apr/include/apr-1  -I/usr/local/apr/include/apr-util-1   -c -o bstrlib.o bstrlib.c
cc -D_LARGEFILE64_SOURCE=1 -g -Wall -I/usr/local/apr/include/apr-1  -I/usr/local/apr/include/apr-util-1   -c -o db.o db.c
cc -D_LARGEFILE64_SOURCE=1 -g -Wall -I/usr/local/apr/include/apr-1  -I/usr/local/apr/include/apr-util-1   -c -o shell.o shell.c
cc -D_LARGEFILE64_SOURCE=1 -g -Wall -I/usr/local/apr/include/apr-1  -I/usr/local/apr/include/apr-util-1   -c -o commands.o commands.c
cc -D_LARGEFILE64_SOURCE=1 -g -Wall -I/usr/local/apr/include/apr-1  -I/usr/local/apr/include/apr-util-1  -lapr-1 -pthread -laprutil-1  devpkg.c bstrlib.o db.o shell.o commands.o   -o devpkg
/tmp/ccZcAm9b.o: In function `main':
/home/zach/Desktop/devpkgzed/devpkg.c:14: undefined reference to `apr_pool_initialize'
/home/zach/Desktop/devpkgzed/devpkg.c:15: undefined reference to `apr_pool_create_ex'
/home/zach/Desktop/devpkgzed/devpkg.c:29: undefined reference to `apr_getopt_init'
/home/zach/Desktop/devpkgzed/devpkg.c:31: undefined reference to `apr_getopt'
</code></pre>

My issue is that I don't really understand how <code>make</code> is coming up with these commands via the CFLAGS that are set.  How can I get the linker options to follow the compilation part instead of the other way around, which is triggering this issue?

