开发者

make not working as expected

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 libop开发者_开发百科t.a

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

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

clean:
    rm -f *.o libopt.a


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜