制作文件错误 [英] Make file error

查看:123
本文介绍了制作文件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- >再presents包括

-> represents "include"

list.c - > list.h

list.c -> list.h

matrix.c - > matrix.h

matrix.c -> matrix.h

smatrix.c - > smatrix.h

smatrix.c -> smatrix.h

smatrix .h文件 - > list.h和matrix.h文件

smatrix h file -> list.h and matrix.h files

test.c以 - > test.h

test.c -> test.h

test.h - > list.h,matrix.h和smatrix.g文件

test.h -> list.h, matrix.h, and smatrix.g files

和现在我有这个makefile

And now I have this 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的文件中的函数的头文件这些功能。所有的头文件都包括加尔东西LIET的文件名

我如何解决这个问题?

-edit-
我改变* o文件用gcc -c而不是gcc -o,现在我得到

-edit- I changed *o file with gcc -c instead of gcc -o and now I am getting

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;
            }
        }
    }

它工作得很好,其中x code4 ......如何解决这个问题呢?

It worked fine with xcode4...How to fix this problem?

推荐答案

您需要添加 -c 选项,以使GCC生成目标文件和 -o名称来命名它。例如:

You need to add the -c option to make gcc generate object file and -o name to name it. Example:

smatrix.o: smatrix.c smatrix.h
    gcc -g -c -o smatrix.o smatrix.c

要解决的第二个问题,添加 -std = C99 切换到GCC参数列表。而且,正如埃文Mulawski提到的,​​你不需要 -o 开关。

To solve the second problem, add the -std=c99 switch to gcc parameter list. And, as Evan Mulawski mentioned, you don't need the -o switch.

smatrix.o: smatrix.c smatrix.h
    gcc -g -std=c99 -c smatrix.c

这篇关于制作文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆