저는 C 언어를 처음 사용합니다. 프로그램을 컴파일하기 위해 다중 모듈 개념을 사용해야하는 과제가 있습니다. '정의되지 않은 참조'오류가 계속 발생합니다. 이 프로그램은 단순히 화씨를 섭씨로 변환합니다. 함수 프로토 타입, 호출 및 정의를 포함하는 하나의 스크립트 만 사용하면 간단하게 작동하지만 다중 모듈 개념에서는 '정의되지 않은 참조'오류가 계속 발생합니다. 세 파일을 모두 다른 폴더 나 같은 폴더에 넣어야합니까?
conversion.c :
/*
* filename: conversion.c
* Purpose: The file contains function prototype
* to convert farenheit to celsius
*/
#include "conversion.h"
//conversion for farenheit to celsius
float convertTemp(float tmp)
{
return ((tmp-32)*0.555);
}
conversion.h :
/*
* FILENAME: conversion.h
* PURPOSE: The file contains function prototype
* for conversion.c
*/
float convertTemp(float tmp);
convert_driver.c :
/*
* FILENAME: convert_driver.c
* PURPOSE: The file contains main() function
* and user interface.
*/
#include <stdio.h>
#include "conversion.h"
int main(void)
{
float x,y;
printf("Please enter your temperature for conversion: \n");
scanf("%f", &x);
y = convertTemp(x);
printf("Converted Temperature: %0.2f\n", y);
return 0;
}
줄에 대한 오류가 계속 발생합니다.
y=convertTemp(x)
어떤 도움을 주시면 감사하겠습니다.
문제는 컴파일 된 객체 를 연결하는 것 입니다.
다음과 같이 소스를 수동으로 컴파일하십시오.
gcc -o convert_driver convert_driver.c conversion.c
이런 식으로 컴파일 후 컴파일러는 링크 할 항목을 알고 있습니다.
소스를 개체로 수동으로 컴파일하고 정적 링커를 사용하여 실행 파일을 생성 할 수도 있습니다.
gcc -c -o convert_driver.o convert_driver.c
gcc -c -o conversion.o conversion.c
ld -o convert_driver convert_driver.o conversion.o
일반적인 IDE의 경우 "프로젝트 생성"옵션이 있는지 확인합니다. 다중 파일 지원은 일반적으로 "프로젝트"개념 내에서 제공됩니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다