의 정의되지 않은 참조는 의 main
에 있습니다.argv [1]을 사용하여 함수를 다른 함수에 전달하고 데이터를 읽는 함수에 대한 정의되지 않은 참조
collect2: error ld returned 1 exit status
질문 구조
- 질문의 세부 주요 기능에 대한
- 코드 -
allouer
이 (=는 할당) 및lire
(= 읽기) (파일allocate_plat.c
라고합니다) proj.c
소스 file - 인수로 filename을 취하여 함수를 사용하여 읽어야합니다.lire
proj.h
헤더 파일 - 구조 정의 및 프로토 타입 기능Makefile
-이 문제가 발생하지만, 읽을 수있는 완성도
- 예 txt 파일에 포함 믿을 수 없다. 정보는
입니다. 1. 이것은 여러 소스 파일을 사용하는 첫 번째 목표입니다. 목표는 http://www.rci-jeux.com/jeux/labychiffres/laby.swf과 같은 게임 보드를 여는 것입니다.
나는 유학 중이며 강사와의 기술 토론에 약간의 어려움이 있으며, 포인터에 대한 이해 또는 적어도 언제 어디서 사용해야하는지 생각해보십시오. * &은 약합니다. proj.c의 명령 줄에서 allocate_plat.c로 전달되는 게임 파일 -이 방법이 효과적이라고 생각하지만 실수를 발견하면이를 지적하십시오. 윤리 강령은 다음과 같습니다 - 구조에 대한 지침을 가지고 있으므로 적절하다고 확신합니다.
내가 뭘 해봤는지 - 현재 상황은 파일 이름 인수를 proj.c
에서 allocate_plat.c
번으로 전달할 때 몇 시간 동안 다림질을해야한다는 결론을 낸다. 나는이 유형의 오류를 본 적이 처음이다. 어디서부터 시작해야할지 모르겠다.
나는 C++ Undefined reference to function implemented and templated in code을 읽었으며 해결책을 볼 수 없습니다.
2. allocate_plat.c
공백을 할당하고 게임 데이터를 읽습니다 (주간 과제에 사용 된 매트릭스 데이터 구조와 유추하여 읽을 수있게되어 있습니다. 그것을 위해 나는 단지 하나의 소스 파일을 사용하여)
#include <stdio.h>
#include <stdlib.h>
#include "proj.h"
int allouer(PLATEAU *PLAT, int nl, int nc, int ldep, int cdep, int larr, int carr, int longdem, int sumdem){
int i,succes;
PLAT->grille = (int**)calloc(nl,sizeof(int*));
PLAT->nl = nl;
PLAT->nc = nc;
PLAT->longdem = longdem;
PLAT->sumdem = sumdem;
PLAT->dep.indl = ldep;
PLAT->dep.indc = cdep;
PLAT->arr.indl = larr;
PLAT->arr.indc = carr;
succes = (PLAT->grille != NULL);
for (i=0; succes && i<nl;i++){
PLAT->grille[i]=(int*)calloc(nc,sizeof(int));
succes = (PLAT->grille[i] != NULL);
}
return succes;
}
int lire(char *nom_fichier, PLATEAU *PLAT){
int i,j,succes, c;
PLATEAU jeu;
FILE *fp;
fp = fopen(nom_fichier, "rt");
if(fp==NULL) {
printf("Erreur d'ouverture du fichier\n");
return 0;
}
c = fscanf(fp,"%d %d",&PLAT->nl,&PLAT->nc);//Read first line
if(c != 2){
printf("Erreur de format de fichier\n");
fclose(fp);
return 0;
}
c = fscanf(fp,"%d %d",&PLAT->dep.indl,&PLAT->dep.indc);//Read second line
if(c != 2){
printf("Erreur de format de fichier\n");
fclose(fp);
return 0;
}
c = fscanf(fp,"%d %d",&PLAT->arr.indl,&PLAT->arr.indc);//Read third line
if(c != 2){
printf("Erreur de format de fichier\n");
fclose(fp);
return 0;
}
c = fscanf(fp,"%d %d",&PLAT->longdem,&PLAT->sumdem);//Read fourth line
if(c != 2){
printf("Erreur de format de fichier\n");
fclose(fp);
return 0;
}
//ALLOCATE THE FILE TO THE STRUCT
succes = allouer(PLAT, PLAT->nl, PLAT->nc, PLAT->dep.indl, PLAT->dep.indc, PLAT->arr.indl, PLAT->arr.indc, PLAT->longdem, PLAT->sumdem);
if(succes==0) {
printf("Erreur d'allocation\n");
fclose(fp);
return 0;
}
for(i=0; i< PLAT->nl; i++){
for(j=0; j<PLAT->nc; j++){
c=fscanf(fp, "%d", &PLAT->grille[i][j]);
if(c != 1){
printf("Erreur de format de fichier\n");
fclose(fp);
return 0;
}
}
}
fclose(fp);
return 1;
}
3.Main 소스 파일 :. proj.c
#include <stdio.h>
#include <stdlib.h>
#include "proj.h"
int main(int argc, char* argv[]){
// char nom_fichier[25];
int choix, choix2, succes;
PLATEAU jeu;
if (argc > 1){
char *nom_fichier = argv[1];
lire(nom_fichier, &jeu);
}
return 0;
}
4.My 헤더 파일 : proj.h
#pragma once
typedef struct position_st{//position st is tag for the type: "struct posiition_st"
int indl;//indice of ligne
int indc;//indice of colonne
}POSITION;
typedef struct element_st{
POSITION valeur;
struct element_st *P_suivant;
}ELEMENT;
typedef struct pile_st{
ELEMENT * P_sommet;
} PILE;
//##########PLATEAU STRUCTURE DEFINITION##############
typedef struct plat_st{
//########## INFORMATION INCLUDED IN THE GAME FILES ###################
POSITION dep;//start position
POSITION arr;//finishing position
int longdem;//length of path requested
int sumdem;//total demanded
int nl;//number of rows in grille
int nc;//number of columns in grille
int ** grille;//Playing table
//########## PART TO DO WITH THE CURRENT GAME ###################
int longcur;//current length
int sumcur;//current total
PILE chemin;//the path
}PLATEAU;
//########## FUNCTION PROTOTYPES ########################
//allouer allocates the variables for the game
int allouer(PLATEAU *, int, int, int, int, int, int, int, int);
//lire reads a game from a file
int lire(char *, PLATEAU *);
5.My makefile
5,:
CC = gcc
CFLAGS = -I #-Wall
DEPS = proj.h
OBJ = proj.o allocate_plat.o
%.o: %.c $(DEPS)
$(CC) $(CFLAGS) -c -o [email protected] $<
proj: $(OBJ)
gcc $(CFLAGS) -o [email protected] $^
6.파일 구조의 예 (아마도 필요한 주석이 없을 것입니다)
4 4// number of orws and columns in board
1 1//starting coordinates (based at 1)
4 4//ending coordinates (based at 1)
11 96//path length and sum of elements of path required
10 13 2 5//board grid
3 15 9 4
8 6 11 14
7 12 1 16
대단히 감사합니다. 문제가있는 곳이라고 생각하지는 않았지만 오류없이 컴파일됩니다. 할 수있을 때 똑딱 거릴거야 ... – Luskentyrian