내 코드에서 일종의 컴파일러/링커 오류가 발생합니다. 대부분 전처리 기 관련이 있습니다. 오류 메시지는 "x의 다중 정의"를 읽습니다. 여기서 x는 lib.c 파일에있는 4 개의 함수 중 하나입니다. 내가 사용하고있는 컴파일러/링커는 GNU GCC 컴파일러가 코드와 함께 패키지되어있다 : 블록여러 정의 ... (링커 오류?)
#includes의 순서를 변경하지 않으려 고 시도했는데, 이것이 내가 링커 오류라고 생각하게 만든다. 컴파일러 오류는 의도적 인 구문 오류를 만들면 컴파일러가 오류 메시지를 표시하지 않고 중단하고 중단한다는 사실입니다.
모든 도움/조언/비평, 감사드립니다!
#include <stdlib.h>
#include "lib.c"
int main()
{
getGradeAverage();
return EXIT_SUCCESS;
}
과 lib.c :
이#include "defs.h"
void getUserName()
{
printf ("please enter the your name:");
studentRecord sr;
scanf("%40[^\n]%*c",&sr.studentName);
}
void getCourse (index)
{
printf("please enter the name of course 1:");
courseRecord cr1;
scanf("%40[^\n]%*c",&cr1.courseName);
do{
printf("please enter a grade for course 1:");
if ((scanf("%i",&cr1.grade))>-2)
{
printf("the grade you entered is not on the scale. please try again:");
fflush(stdin);
continue;
}
} while(true);
printf("please enter the name of course 2:");
courseRecord cr2;
scanf("%40[^\n]%*c",&cr2.courseName);
do{
printf("please enter a grade for course 1:");
if ((scanf("%i",&cr2.grade))>-2)
{
printf("the grade you entered is not on the scale. please try again:");
fflush(stdin);
continue;
}
} while(true);
}
void GPAPrint()
{
int GPA;
studentRecord sr;
courseRecord cr1;
courseRecord cr2;
printf("Student name: %s\n",&sr.studentName);
}
void getGradeAverage()
{
int index=1;
getUserName();
getCourse(index);
GPAPrint();
return (0);
}
defs.h 파일이 #include를 대부분 들어 있으므로, 여기에도 관련이 여기
은 main.c에 파일입니다 및 구조체.#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
#define MAX_LENGTH 40
typedef struct courseRecord
{
char courseName [MAX_LENGTH+1];
int grade;
}courseRecord;
typedef struct studentRecord
{
char studentName [MAX_LENGTH+1];
char courseName[2];
}studentRecord;
정확히 "내 코드에서 일종의 컴파일러/링커 오류"가 무엇입니까? BTW 헤더 파일에 4 개의 함수에 대한 함수 프로토 타입을 넣어야합니다. –
아래로 더 자세히 지정했습니다. 오류 메시지는 "multiple definitions of ..."입니다. 아니면 다른 것을 의미합니까? – Thefoilist
'x' 중. 'x' 무엇입니까? –