- >代表 「包括」Make文件錯誤
list.c - > list.h
matrix.c - > matrix.h
smatrix.c - > smatrix.h
SMATRIX .h文件 - > list.h和matrix.h文件
test.c以 - > test.h
test.h - > list.h, matrix.h和smatrix.g文件
現在我有這個Makefile
all: run
run: test.o list.o matrix.o smatrix.o
gcc test.o list.o matrix.o smatrix.o -o matrix-mul
list.o: list.c list.h
gcc -g list.c
matrix.o: matrix.c matrix.h
gcc -g matrix.c
smatrix.o: smatrix.c smatrix.h
gcc -g smatrix.c
test.o: test.c test.h
gcc -g test.c
現在我得到
Undefined symbols for architecture x86_64:
"_make_matrix", referenced from: //make_matrix defines in matrix.h
_main in cctU8RoB.o
"_print_matrix", referenced from://print_matrix defines in list.h
_main in cctU8RoB.o
"_make_smatrix", referenced from://make_smatrix defines in smatrix.h
_main in cctU8RoB.o
"_multiply_by_vector", referenced from://muliply_by_vector defines in smatrix.h
_main in cctU8RoB.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [test.o] Error 1
我打電話這是在其他文件中定義的那些功能test.c和test.h包含test.c文件中調用函數的所有頭文件。所有頭文件都包含gard東西liet 文件名
我該如何解決這個問題?
CNC中 我改變* o文件用gcc -c代替gcc的-o,現在我得到
matrix.c:33: error: ‘for’ loop initial declaration used outside C99 mode
matrix.c:38: error: ‘for’ loop initial declaration used outside C99 mode
matrix.c:44: error: ‘for’ loop initial declaration used outside C99 mode
matrix.c: In function ‘make_matrix_k’:
matrix.c:58: error: ‘for’ loop initial declaration used outside C99 mode
matrix.c: In function ‘print_matrix’:
matrix.c:73: error: ‘for’ loop initial declaration used outside C99 mode
matrix.c:74: error: ‘for’ loop initial declaration used outside C99 mode
//for loop in matrix.c file
for(size_t i=0; i < height; i++){
//m->data[i] = malloc(sizeof(int)*width);
m->data[i] = calloc(width, sizeof(int));
if(m->data[i] == NULL){
for(size_t j = 0; j < i; j++) free(m->data[j]);
free(m->data);
free(m);
return 0;
}
if(opt == nonzero_matrix_k_off){
for(size_t j = 0; j < width; j++){
m->data[i][j] = 2;
}
}
}
它好工作與xcode4 ...如何解決這個問題?
對於* .o文件,您需要使用'gcc -c -g ...'。 – 2011-03-25 12:39:19
如果您嘗試手動運行生成文件中的命令,會發生什麼情況?第一個錯誤發生在哪裏?你究竟輸入了什麼,並拋出了什麼錯誤? – 2011-03-25 12:39:58