Closed. This question is off-topic。它当前不接受答案。
想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。
4年前关闭。
好吧,所以我有这段代码应该从文件中读取文本并进行一些计算,对于这个问题来说,这并不是太重要。当我尝试编译它时,出现此错误(文件名为pp3.c)
这是我的代码
将错别字声明为函数没有帮助:
想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。
4年前关闭。
好吧,所以我有这段代码应该从文件中读取文本并进行一些计算,对于这个问题来说,这并不是太重要。当我尝试编译它时,出现此错误(文件名为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++;
}
}
最佳答案
您的来源中有错字。 sovle
不是solve
:
它抱怨的是这里:
if(sovle(posx, posy,oldposy,oldposx))
printmaze();
将错别字声明为函数没有帮助:
int findstart();
int sovle(int,int,int,int);
int printmaze();
关于c - 在gcc中编译时 undefined reference ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33115027/