Makefile'm hata yapmadan çalışmaya başlamasında sorun yaşıyorum. Sahip olduğum ilk konu, ana tanımlanmamış bir referanstır. Produc.c dosyasında bir işlev olarak ana var. İkinci sorun, SearchCustomer() için tanımlanmamış bir referanstır.(.text + 0x20): "ana" ve tanımsız başvuru referansı için tanımsız başvuru
hatası:
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
makefile:
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
Kod ** çok ** uzun. Sorununuzu daraltın ve bir [Kısa, Kendini İçeren, Doğru (Tamamlayıcı), Örnek] (http://sscce.org/) sağlayın. –
Bir kaç öneri: "ana" tarifinde: $ (COMPILER) -o $ @ $^$ (LDFLAGS) yazıp 'LDPLAGS'de' -pthread' yazabilirsiniz. Diğer kurallarda ** bir kez ** yazabilirsiniz: '% .o:% .c' ve tarif olarak: $ (COMPILER) $ (CCFLAGS) -c -o $ @ $ <' (ve ** değil * * .h'yi derleyiciye verin!) ve daha sonra özel hedeflere bağımlılık ekleyin, örneğin: "producer.o: shared.h other_header.h" ve "consumer.o: shared.h yet_another_header.h" vb. – Shahbaz
Diğer birkaç öneri: Sadece make yapmak yerine 'make' yerine' $ (MAKE) 'işlevini kullanın. Ayrıca, gereksiz çıktıların çift satırlarını önlemek için '--no-print-directory 'vermek isteyebilirsiniz. Ayrıca, C için CFLAGS'yi kullanın (C++ ile karıştırılabilecek 'CCFLAGS' yerine). – Shahbaz