在gcc中编译时未定义的引用

时间:2015-10-14 01:07:48

标签: c gcc undefined

好吧所以我有这个代码应该从文件中读取文本并做一些对这个问题不太重要的计算。当我尝试编译它时,我收到此错误(文件名为pp3.c)

/tmp/ccnZaQld.o:pp3.c:(.text+0x5f): undefined refrence to 'sovle' 
/tmp/ccnZaQld.o:pp3.c:(.text+0x5f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol 'solve'
collect2: error: ld returned 1 exit status

这是我的代码

#include <stdio.h>
#define SIZE 100

char buff[SIZE][SIZE];
int initialize();
int read(char*);
int findstart();
int sovle(int,int,int,int);
int printmaze();
int posx, posy, oldposy, oldposx;


int main(int argc, char* argv[]){
    initialize();
    read(argv[1]);
    findstart();
    if(sovle(posx, posy,oldposy,oldposx))
        printmaze();
    else
        printf("maze is unsolveable");
}

int initialize(){
    int i;
    int m;
    for(i=0; i<SIZE; i++){
        for(m=0; i<SIZE; i++){
            buff[i][m]='0';
        }
    } 
}

int read(char* m88){
    FILE* myfile = fopen(m88, "r");
    int linenum = 0;
    while(fgets(buff[linenum], SIZE, myfile)!=NULL){
        linenum++;
    }
    fclose(myfile);
}

int findstart(){
    int i,m;
    for(i=0; i<SIZE; i++){
        for(m=0; i<SIZE; i++){
            if (buff[i][m]== 'S'){
                posx = m;
                posy = i;
                oldposy = i;
                oldposx = m;
                return 1;
            }   
        }
    } 
}

int solve(int x, int y, int oldx, int oldy){
    if(buff[y][x+1] != 'x' && x+1 != oldposx){
        if(buff[y][x+1] == '$')return 1;
        if(solve(y,x+1,y,x)){
            buff[y][x+1] = '*';
            return 1;
        }
    }
    if(buff[y][x-1] != 'x' && x-1 != oldposx){
        if(buff[y][x-1] == '$')return 1;
        if(solve(y,x-1,y,x)){
            buff[y][x-1] = '*';
            return 1;
        }
    }
    if(buff[y+1][x] != 'x' && y+1 != oldposy){
        if(buff[y+1][x] == '$')return 1;
        if(solve(y+1,x,y,x)){
            buff[y+1][x] = '*';
            return 1;
        }
    }
    if(buff[y-1][x] != 'x' && y-1 != oldposy){
        if(buff[y-1][x] == '$')return 1;
        if(solve(y-1,x,y,x)){
            buff[y-1][x] = '*';
            return 1;
        }
    }
}

int printmaze(){
    int i;
    while(buff[i][0]!= '0'){
        printf("%s", buff[i]);
        i++;
    }
}

1 个答案:

答案 0 :(得分:1)

你的来源有拼写错误。 sovle不是solve

他们抱怨的是:

if(sovle(posx, posy,oldposy,oldposx))
    printmaze();

您已将拼写错误声明为函数,这无济于事:

int findstart();
int sovle(int,int,int,int);
int printmaze();