안녕하세요. 저는 .c 파일간에 글로벌 변수를 공유하는 방법을 궁금합니다.
코드를 추가하려고하지만 오류가 발생합니다..c 파일간에 글로벌 변수 공유
TEST.C 파일
#include <stdio.h>
int max = 50;
int main()
{
printf("max %d", max); // result max 50
}
pass.h
extern int max;
passed.c
#include <stdio.h>
#include "pass.h"
max;
int main()
{
printf("pass %d \n", max);
return 0;
}
내가 passed.c를 컴파일 할 때하지만 오류가 따라야 얻을
Undefined symbols for architecture x86_64:
"_max", referenced from:
_main in passed-iOMugx.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
아무도 도와 줄 수 있습니까? 정말 고맙습니다.
두 개의 main() 함수가 있음을 실제로 의미합니까? –
왜 두 가지 주요 기능이 있습니까? 그들은 프로그램을 분리합니까 아니면 하나의 프로그램으로 함께 연결될 것입니까? 그들이 하나의 프로그램에서 함께 링크되어 있다면 그것은 최대에 대해 불평해서는 안됩니다 - 그것은 중복되는 주요 기능에 대해 불평해야합니다. –
예, [다른 .c 파일간에 변수를 공유하는 방법은 무엇입니까?] ( –