链接Makefile时出错(退出代码1)

时间:2019-11-09 18:26:02

标签: c++ c++11 makefile ubuntu-18.04 makefile-errors

这是我第一次使用makefile。使用“ clang”时出现“链接器命令失败,退出代码为1”错误。

我只是将.h文件链接到makefile中,并在ubuntu终端中运行make all。

CC_EXEC = clang
CC_FLAGS = -g

CC = ${CC_EXEC} ${CC_FLAGS}

BUILD_DIR = build

all: executable.out

executable.out:  ${BUILD_DIR}/main.o  ${BUILD_DIR}/UTrelloInterface.o  ${BUILD_DIR}/User.o  ${BUILD_DIR}/List.o  ${BUILD_DIR}/Task.o
    clang -g ${BUILD_DIR}/main.o ${BUILD_DIR}/UTrelloInterface.o ${BUILD_DIR}/User.o ${BUILD_DIR}/List.o ${BUILD_DIR}/Task.o -o ${BUILD_DIR}/executable.out


${BUILD_DIR}/main.o: main.cpp UTrelloInterface.h User.h List.h Task.h
    ${CC} -c main.cpp -o ${BUILD_DIR}/main.o

${BUILD_DIR}/User.o: User.cpp User.h
    ${CC} -c User.cpp -o ${BUILD_DIR}/User.o

${BUILD_DIR}/List.o: List.cpp List.h
    ${CC} -c List.cpp -o ${BUILD_DIR}/List.o

${BUILD_DIR}/Task.o: Task.cpp Task.h
    ${CC} -c Task.cpp -o ${BUILD_DIR}/Task.o
${BUILD_DIR}/UTrelloInterface.o: UTrelloInterface.cpp UTrelloInterface.h Task.h List.h User.h
    ${CC} -c UTrelloInterface.cpp -o ${BUILD_DIR}/UTrelloInterface.o

.PHONY: clean
clean:
    rm -rf build/ && mkdir -p build

我恰好收到此错误:

clang: error: linker command failed with exit code 1 (use -v to see invocation)
makefile:11: recipe for target 'executable.out' failed
make: *** [executable.out] Error 1

使用g ++编译器时出现此错误:

g++ -g -c User.cpp -o build/User.o
g++ -g build/main.o build/UTrelloInterface.o build/User.o build/List.o build/Task.o -o build/executable.out
/usr/bin/ld: build/main.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
makefile:11: recipe for target 'executable.out' failed
make: *** [executable.out] Error 1

我该怎么办?

0 个答案:

没有答案
相关问题