오류없이 작동하도록 makefile을 가져 오는 데 문제가 있습니다. 내가 가진 첫 번째 문제는 main에 대한 정의되지 않은 참조입니다. 내 producer.c 파일에 main이 함수로 있습니다. 두 번째 문제는 SearchCustomer()에 대한 정의되지 않은 참조입니다.(.text + 0x20) : 'main'에 대한 정의되지 않은 참조 및 함수에 대한 정의되지 않은 참조
오류 :
bash-4.1$ make
gcc -Wall -c producer.c shared.h
gcc -Wall -c consumer.c shared.h
gcc -Wall -c AddRemove.c shared.h
gcc -pthread -Wall -o producer.o consumer.o AddRemove.o
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
AddRemove.o: In function `AddRemove':
AddRemove.c:(.text+0xb1): undefined reference to `SearchCustomer'
AddRemove.c:(.text+0x1e9): undefined reference to `SearchCustomer'
AddRemove.c:(.text+0x351): undefined reference to `SearchCustomer'
collect2: ld returned 1 exit status
make: *** [producer] Error 1
메이크 :
COMPILER = gcc
CCFLAGS = -Wall
all: main
debug:
make DEBUG=TRUE
main: producer.o consumer.o AddRemove.o
$(COMPILER) -pthread $(CCFLAGS) -o producer.o consumer.o AddRemove.o
producer.o: producer.c shared.h
$(COMPILER) $(CCFLAGS) -c producer.c shared.h
consumer.o: consumer.c shared.h
$(COMPILER) $(CCFLAGS) -c consumer.c shared.h
AddRemove.o: AddRemove.c shared.h
$(COMPILER) $(CCFLAGS) -c AddRemove.c shared.h
ifeq ($(DEBUG), TRUE)
CCFLAGS += -g
endif
clean:
rm -f *.o
코드가 ** 너무 ** 길다. 문제를 줄이고 [짧은, 자기 포함, 올바른 (편집 가능한), 예] (http://sscce.org/)를 제공하십시오. –
몇 가지 제안 사항 :'main' 제조법에서는'$ (COMPILER) -o $ @ $^(LDFLAGS)'라고 쓰고'LDFLAGS'에'-pthread '를 넣을 수 있습니다. 다른 규칙들에서는 ** once ** :'% .o : % .c'와 recipe :'$ (COMPILER) $ (CCFLAGS) -c -o $ @ $ <'를 쓸 수 있습니다. * 컴파일러에'.h '를 줘라.) 그리고 나중에 특별한 타겟을위한 의존성을 추가한다. 예를 들면 :'producer.o : shared.h other_header.h'와'consumer.o : shared.h yet_another_header.h' 등. – Shahbaz
몇 가지 다른 제안 : 호출 된 make에 대한 명령 행 플래그를 유지하려면'make '대신'$ (MAKE)'를 사용하십시오. 또한'--no-print-directory'를 사용하여 몇 줄의 쓸모없는 출력을 방지 할 수 있습니다. 또한 C에 대해'CFLAGS'를 사용하십시오 (C++과 혼동을 줄 수있는'CCFLAGS' 대신에). – Shahbaz