好的,我已经尽可能多地尝试了(不太了解递归制作)。所以希望有人能够对这个问题有所了解。这是我的目录结构列表...
SAB->
-- Makefile
-- Readme.txt
-- bin -> Empty
-- obj -> Empty
-- src -> Another makefile in here with c sources
|--> transfer -> Another makefile in here with sources
|--> prs_socket -> Another makefile in here with sources
下面是有问题的品牌,下面是另一个品牌文件。来自prs_socket目录的那个。后者Makefile并没有将-fPIC开关放在那里。
# S.A.B. project main makefile
CC=gcc
CFLAGS=-std=c99 -Wall -Wextra -pedantic
LDFLAGS=
MAKEFILE = Makefile
TARGETS = build
all: $(TARGETS)
.PHONY: build clean install uninstall
build:
@echo Building S.A.B.
cd src && make
cd src/transfer && make
cd src/prs_socket && make
cd src/prs_socket/tests && make
clean:
@echo Cleaning project...
@rm -f *~
cd src/prs_socket && make clean
cd src/prs_socket/tests && make clean
cd src/transfer && make clean
cd src && make clean
@echo Done cleaning!
install:
@echo Installing... S.A.B.
cd src/prs_socket && make install
cd src/transfer && make install
cd src && make install
@echo Done installing!
uninstall:
@echo Uninstalling... S.A.B.
cd src/prs_socket && make uninstall
cd src/transfer && make uninstall
cd src && make uninstall
@echo Done uninstalling!
这是prs_socket目录的makefile,它不像它应该放置-fPIC。
CC=gcc
CFLAGS+=-fPIC
LDFLAGS=-shared -fPIC -Wl,-soname,libprs_socket.so.1 -lc
TARGET=libprs_socket.so.1.0
BINDIR=../../bin
OBJDIR=../../obj
SRCDIR=../../src
INSTALLDIR?=/opt
SOURCES = $(wildcard $(SRCDIR)/prs_socket/*.c)
INCLUDES = $(wildcard $(SRCDIR)/prs_socket/*.h)
OBJECTS = $(SOURCES:$(SRCDIR)/prs_socket/%.c=$(OBJDIR)/%.c.o)
all: linux
linux: $(BINDIR)/$(TARGET)
$(BINDIR)/$(TARGET): $(OBJECTS)
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
$(OBJECTS) : $(OBJDIR)/%.c.o: $(SOURCES)
@$(CC) $(CFLAGS) -c -o $@ $<
.PHONY: clean install uninstall
clean:
@echo Cleaning up...
@rm -f *~ $(OBJDIR)/*.c.o $(BINDIR)/$(TARGET)
@echo Done cleaning!
install:
@echo Installing...
@mkdir -p $(INSTALLDIR)/include/prs_socket
@cp $(SRCDIR)/prs_socket/socket.h $(INSTALLDIR)/include/socket.h
@cp $(BINDIR)/$(TARGET) $(INSTALLDIR)/lib
@ln -sf $(INSTALLDIR)/lib/$(TARGET) $(INSTALLDIR)/lib/$(TARGET).1
@ln -sf $(INSTALLDIR)/lib/$(TARGET) $(INSTALLDIR)/lib/libprs_socket.so
@chmod 0755 $(INSTALLDIR)/lib/$(TARGET)
@chmod 0755 $(INSTALLDIR)/lib/libprs_socket.so.1
@chmod 0755 $(INSTALLDIR)/lib/libprs_socket.so
@echo Install finished!
uninstall:
@echo Uninstalling...
@rm -rf $(INSTALLDIR)/include/prs_socket
@rm -f $(INSTALLDIR)/lib/libprs_socket.so.1
@rm -f $(INSTALLDIR)/lib/libprs_socket.so
@rm -f $(INSTALLDIR)/lib/$(TARGET)
@echo Uninstall finished.
提前致谢,如果需要更多信息,请告知我们。
更新:以下是运行make后显示的内容,删除@。
philip@slackbox:~/debug/SAB$ make
Building S.A.B.
cd src && make
make[1]: Entering directory '/home/philip/debug/SAB/src'
gcc -std=c99 -Wall -Wextra -pedantic -c -o ../obj/socket.c.o ../src/socket.c
gcc -std=c99 -Wall -Wextra -pedantic -c -o ../obj/helper.c.o ../src/helper.c
gcc -std=c99 -Wall -Wextra -pedantic -c -o ../obj/espeech.c.o ../src/espeech.c
gcc -std=c99 -Wall -Wextra -pedantic -c -o ../obj/main.c.o ../src/main.c
gcc -std=c99 -Wall -Wextra -pedantic -c -o ../obj/transfer.c.o ../src/transfer.c
gcc -std=c99 -Wall -Wextra -pedantic ../obj/socket.c.o ../obj/helper.c.o ../obj/espeech.c.o ../obj/main.c.o ../obj/transfer.c.o -o ../bin/SAB -lespeak
make[1]: Leaving directory '/home/philip/debug/SAB/src'
cd src/transfer && make
make[1]: Entering directory '/home/philip/debug/SAB/src/transfer'
gcc -std=c99 -Wall -Wextra -pedantic -c main.c -o ../../obj/sab_transfer.c.o
gcc -std=c99 -Wall -Wextra -pedantic ../../obj/sab_transfer.c.o ../../obj/transfer.c.o ../../obj/socket.c.o -o ../../bin/SAB_transfer
make[1]: Leaving directory '/home/philip/debug/SAB/src/transfer'
cd src/prs_socket && make
make[1]: Entering directory '/home/philip/debug/SAB/src/prs_socket'
gcc -shared -Wl,-soname,libprs_socket.so.1 -lc -o ../../bin/libprs_socket.so.1.0 ../../obj/socket.c.o
/usr/lib64/gcc/x86_64-slackware-linux/5.3.0/../../../../x86_64-slackware-linux/bin/ld: ../../obj/socket.c.o: relocation R_X86_64_32S against `create_bind' can not be used when making a shared object; recompile with -fPIC
../../obj/socket.c.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:22: recipe for target '../../bin/libprs_socket.so.1.0' failed
make[1]: *** [../../bin/libprs_socket.so.1.0] Error 1
make[1]: Leaving directory '/home/philip/debug/SAB/src/prs_socket'
Makefile:14: recipe for target 'build' failed
make: *** [build] Error 2
philip@slackbox:~/debug/SAB$