-> представляет "включить"
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 files
А теперь у меня есть этот make-файл
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 filename
Как я могу решить эту проблему ??
-edit-
Я изменил * 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 все работало нормально ... Как решить эту проблему?