views:

39

answers:

2

Hey guys I wrote a makefile which work perfectly fine on my 27" iMac at home running Snow Leopard, however when I uploaded it to my uni's computer, a 24" running Snow Leopard as well, it gets the following:

gcc -std=c99 -Wall -pedantic -Werror -c print.c
gcc -std=c99 -Wall -pedantic -Werror -c process.c
gcc -std=c99 -Wall -pedantic -Werror -c sync.c
gcc -std=c99 -Wall -pedantic -Werror -c option_a.c
gcc -std=c99 -Wall -pedantic -Werror -c option_m.c
gcc -std=c99 -Wall -pedantic -Werror -c option_n.c
gcc -std=c99 -Wall -pedantic -Werror -c option_p.c
gcc -std=c99 -Wall -pedantic -Werror -c option_r.c
gcc -std=c99 -Wall -pedantic -Werror -c option_u.c
gcc -std=c99 -Wall -pedantic -Werror -c option_v.c
ar -rc libopt.a option_a.o option_m.o option_n.o option_p.o option_r.o option_u.o option_v.o
gcc -std=c99 -Wall -pedantic -Werror -o mysync mysync.c print.o process.o sync.o libproj2.a libopt.a
libproj2.a: could not read symbols: Archive has no index; run ranlib to add one
collect2: ld returned 1 exit status
make: *** [mysync] Error 1

The following is my makefile:

PROJECT = mysync
COMPILE = gcc -std=c99 -Wall -pedantic -Werror
OPT_OBJ = option_a.o option_m.o option_n.o option_p.o option_r.o option_u.o option_v.o
MAIN = print.o process.o sync.o

$(PROJECT): $(PROJECT).c $(MAIN) libproj2.a libopt.a
    $(COMPILE) -o mysync $(PROJECT).c $(MAIN) libproj2.a libopt.a

libopt.a: $(OPT_OBJ)
    ar -rc libopt.a $(OPT_OBJ)

%.o: %.c $(PROJECT).h
    $(COMPILE) -c $<

clean:
    rm -f *.o libopt.a
A: 

The error is telling you the problem. You need to run ranlib on the archive. However, your entire Makefile can be simplified a lot. If you rely on default rules, don't need the archive for something else, and use gnu make, your entire Makefile can be reduced to:

PROJECT = mysync
CC = gcc
CFLAGS = -std=c99 -Wall -pedantic -Werror
OPT_OBJ = option_a.o option_m.o option_n.o option_p.o option_r.o option_u.o option_v.o
MAIN = print.o process.o sync.o

all: $(PROJECT)
mysync: $(MAIN) $(OPT_OBJ)
clean:
    rm -f *.o

NOTE: this ammended Makefile ignore the mysync.h dependency. You can recover that with lines like:

$(MAIN): $(PROJECT).h

In other words: use the standard conventions (CC, CFLAGS), and don't bother building a library.

William Pursell
Hey thanks for the advice. Didn't know that I can simplify a makefile that with default rules. However I'm still having the problem. One, ranlib doesn't work, it's still displaying the error after I run it. Two, I think you mistook the error to be with libopt.a, but in fact it's with libproj2.a, which is a supplied file which is supposed to work.
jon2512chua
@jon2512chua -- you are correct, I did not notice that the problem is with libproj2.a. What happens when you run ranlib on libproj2.a?
William Pursell
ranlib: libproj2.a: Malformed archive
jon2512chua
@jon2512chua (Sorry for the delay) It sounds like there is a problem with the distribution. Whoever is providing the source for the app you are building should either be giving you 3 distinct projects (one for each library, and one for the app) or one self-contained project that includes source for the entire app (and no libraries). You should report the problem as a bug to the person providing libproj2.a and request source for that library so that you can build it.
William Pursell
Yup I came to that solution as well. Thanks for your help.
jon2512chua
+1  A: 

The problem lies with the provided libproj2.a. Contact library provider for support.

jon2512chua