Hi,
I'm fighting with make for hours and I rly don't know where is my problem. I need to have a static lib libxml.a and an application (make.c) which uses it.
I tried to compile it under GCC 4.4.5 and 4.5.0 and the compilation run fine. But under GCC 4.3.2 I get:
gcc -Wall -O2 -c src/file_handler.o src/stack.o src/msg.o src/enc_validator.o src/dfa.o src/compute.o
gcc: src/file_handler.o: linker input file unused because linking not done
gcc: src/stack.o: linker input file unused because linking not done
gcc: src/msg.o: linker input file unused because linking not done
gcc: src/enc_validator.o: linker input file unused because linking not done
gcc: src/dfa.o: linker input file unused because linking not done
gcc: src/compute.o: linker input file unused because linking not done
gcc -Wall -O2 -c src/main.c
ar cr libxml.a src/file_handler.o src/stack.o src/msg.o src/enc_validator.o src/dfa.o src/compute.o
ranlib libxml.a
gcc -Wall -O2 -static -o xml-valid main.o -lm -L. -lxml
./libxml.a: could not read symbols: Archive has no index; run ranlib to add one
collect2: ld returned 1 exit status
make: *** [xml-valid] Error 1
My makefile with two linking GCC settings:
# Binary name
program=xml-valid
# Input dir
input=src/
# Lib name
lib=xml
# obj files.
OBJ=${input}file_handler.o ${input}stack.o ${input}msg.o ${input}enc_validator.o ${input}dfa.o ${input}compute.o
SRC=${input}file_handler.c ${input}stack.c ${input}msg.c ${input}enc_validator.c ${input}dfa.c ${input}compute.c ${input}main.c
HEAD=${input}file_handler.h ${input}stack.h ${input}msg.h ${input}enc_validator.h ${input}dfa.h ${input}compute.h
# Compiler C
CC=gcc
# Compiler flags
CFLAGS=-Wall -O2
.PHONY: build
.PHONY: clean
# make build - implicit one
build: ${program}
# make clean to remove obsolete files
clean:
rm ${input}*.o
rm *.a
# Final target of compilation
${program}: ${OBJ}
${CC} ${CFLAGS} -c ${OBJ}
${CC} ${CFLAGS} -c ${input}main.c
ar cr lib${lib}.a ${OBJ}
ranlib lib${lib}.a
${CC} ${CFLAGS} -static -o ${program} main.o -lm -L. -l${lib}
mv main.o ${input}main.o
# Final target of compilation
#${program}: ${OBJ}
# ${CC} ${CFLAGS} -c ${OBJ}
# ar rcs lib${lib}.a ${OBJ}
# ranlib lib${lib}.a
# ${CC} ${CFLAGS} -static ${input}main.c -L. -l${lib} -o ${program}
# mv main.o ${input}main.o
# Bound obj to headers
${OBJ}: ${HEAD}
Any help appreciated.