I have a C project that will not link correctly, and I suspect this because the -s flag needs to be passed to the gcc ld program. Because of this flag, gcc sees any linked library specified as an option in front of * .c files as unnecessary and will not link them.
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
When I run this makefile, I get the following.
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'
My problem is that I really do not understand how make approaches these commands through installed CFLAGS. How can I get linker options to follow the compilation part, and not vice versa, what causes this problem?
source share