2011-04-03 15 views
11

क्यों जब मैं अपने makefile के साथ अपने कार्यक्रम संकलन मैं प्राप्त है कि:फ़ाइल समस्या बनाओ?

gcc -Wall -pedantic src/main.c -o _wk/main.o 
src/main.c:9:11: warning: C++ style comments are not allowed in ISO C90 
src/main.c:9:11: warning: (this will be reported only once per input file) 
src/main.c: In function ‘initialiseStructItimerval’: 
src/main.c:46: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘__suseconds_t’ 
src/main.c: In function ‘stockeRetard’: 
src/main.c:71: warning: ISO C90 forbids mixed declarations and code 
src/main.c: In function ‘main’: 
src/main.c:141: warning: ISO C90 forbids mixed declarations and code 
src/main.c:139: warning: unused variable ‘i’ 
Debut de l'edition des liens... 
cd _wk ; gcc -o ../test main.o 
main.o: In function `_start': 
(.text+0x0): multiple definition of `_start' 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 0 has invalid symbol index 12 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 1 has invalid symbol index 13 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 2 has invalid symbol index 2 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 3 has invalid symbol index 2 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 4 has invalid symbol index 12 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 5 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 6 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 7 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 8 has invalid symbol index 2 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 9 has invalid symbol index 2 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 10 has invalid symbol index 13 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 11 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 12 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 13 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 14 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 15 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 16 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 17 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 18 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 19 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 20 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 21 has invalid symbol index 14 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 22 has invalid symbol index 22 
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_line): relocation 0 has invalid symbol index 2 
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:/build/buildd/eglibc-2.11.1/csu/../sysdeps/i386/elf/start.S:119: first defined here 
main.o:(.rodata+0x0): multiple definition of `_fp_hw' 
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata+0x0): first defined here 
main.o: In function `_fini': 
(.fini+0x0): multiple definition of `_fini' 
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o:(.fini+0x0): first defined here 
main.o:(.rodata+0x4): multiple definition of `_IO_stdin_used' 
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here 
main.o: In function `__data_start': 
(.data+0x0): multiple definition of `__data_start' 
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.data+0x0): first defined here 
main.o: In function `__data_start': 
(.data+0x4): multiple definition of `__dso_handle' 
/usr/lib/gcc/i486-linux-gnu/4.4.3/crtbegin.o:(.data+0x0): first defined here 
main.o: In function `_init': 
(.init+0x0): multiple definition of `_init' 
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o:(.init+0x0): first defined here 
/usr/lib/gcc/i486-linux-gnu/4.4.3/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__' 
main.o:(.dtors+0x4): first defined here 
collect2: ld returned 1 exit status 
make: *** [all] Erreur 1 

मेरे makefile यह है:

CC=gcc 
LD=gcc 
C_FLAGS= -Wall -pedantic 


#Dossier de workarea pour la generation 
RWK=_wk 

#Liste des dossier dans lesquels effectuer la recherche ordonnee 
DIRS= \ 
src \ 
bin \ 
$(RWK) 

#Definition de la liste des sources C a compiler 
SRC_C=$(shell (for src in $$(find . -type f -name *.c) ; do basename $$src ; done)) 

#Liste des fichiers objets 
C_OBJS=$(SRC_C:.c=.o) 

vpath %.c $(DIRS) 

#Regle principale 
all: init_wk $(C_OBJS) 
    @echo "Debut de l'edition des liens..." 
    cd $(RWK) ; $(LD) -o test $(C_OBJS) 
    @echo "Compilation terminee." 

#Regle de generation des fichier c->o 
%.o : %.c 
    @echo "Compilation des .c : $<" 
    $(CC) $(C_FLAGS) $< -o $(RWK)/[email protected] 

#Regle a appeler pour le nettoyage de RWK 
clean: 
    @echo "Nettoyage du dossier de travail" 
    @if [ -d $(RWK) ] ; then rm -rf $(RWK) ; fi 

#Regle d'initialisation de la workarea 
init_wk: clean 
    @echo "Creation du dossier de travail..." 
    @mkdir $(RWK) 
    @if [ -e ./out ]; then echo "Existe deja"; else mkdir ./out; fi 

लेकिन जब मैं इस तरह एक साधारण makefile के साथ और के साथ कोई फ़ोल्डर शामिल किए जाने की कोशिश मैं 'कोई त्रुटि किया है:

CC=gcc 
LD=gcc 
BIN = hello 
SRCS=$(wildcard *.c) 
OBJS = $(SRCS:.c=.o) 
DEPS = $(SRCS:.c=.d) 
CFLAGS = -W -Wall -pedantic 
all: $(BIN) 
$(BIN): $(OBJS) 
    $(LD) -o [email protected] $(OBJS) 
%.o: %.c 
    $(CC) -o [email protected] -c $< $(CFLAGS) 
%.d: %.c 
    $(CC) $(CFLAGS) -MM -MD -o [email protected] $< 
-include $(DEPS) 
.PHONY: clean distclean 
clean: 
    rm -rf $(OBJS) 

इस लंबी पोस्ट के लिए खेद है, लेकिन मैं अपनी गलती समझ में नहीं आता:/

+0

आप कुछ चेतावनियों से छुटकारा पाने के लिए '-std = c99' भी जोड़ सकते हैं। वास्तव में –

उत्तर

18

जब केवल एक मॉड्यूल संकलन (उन्हें जोड़ने नहीं), एक संकलक पैरामीटर के रूप में -c जोड़ने यह जोड़ने से रखने के लिए प्रत्येक बार सी/सी ++ रनटाइम।

आप एक निष्पादन योग्य या लाइब्रेरी फ़ाइल प्राप्त करना चाहते हैं जब, -c न जोड़ें। यदि आप एक .o फ़ाइल प्राप्त करना चाहते हैं, तो -c जोड़ें।

8
%.o : %.c 
    @echo "Compilation des .c : $<" 
    $(CC) $(C_FLAGS) $< -o $(RWK)/[email protected] 

यहां कोई समस्या है: -c विकल्प के बिना, gcc संकलित करेगा और लिंक करेगा। इस के साथ प्रयास करें:

$(CC) $(C_FLAGS) -c $< -o $(RWK)/[email protected] 

इसके अलावा, यह करने के लिए और अधिक आम है $(CFLAGS)$(C_FLAGS) से

+0

। आपकी सहायता के लिए धन्यवाद. मैं इसे कैसे भूल सकता हूं-_-। इसके लिए फिर से धन्यवाद;) – Liszto

3

मुझे एक ही समस्या थी। मैंने अपने मुख्य समारोह को तेजी से हटा दिया था। आप जांच सकते हैं कि आपका अभी भी वहां है।

संबंधित मुद्दे