나는 간단한 Coleole C 응용 프로그램을 만드는 동안 코드 블록에 모든 파일을 포함 시켰지만이 오류는 내가 매크로를 정의 할 때 발생합니다. 나는 링커가 프로젝트의 모든 파일을 링크 할 수 없다고 생각합니다 .i 파일에 test1.c 및 test1.h 코드에 포함 된 두 개의 파일이 아래에 표시된 것과 같습니다.코드 블록에서 프로젝트를 빌드하는 중 오류가 발생했습니다.
파일 ::::: test1.c
\ 문서 \ Myprojects \ 내 C PROJ \ 테 \ test1.c ||에서 :#include<stdio.h>
void m();
#include "test1.h"
#define DS==1
int main(){
return 0;
}
파일 :::: test1.h를
#ifndef TEST1_H_INCLUDED
#define TEST1_H_INCLUDED
#if DS ==1
void m(){
printf("hello DS==1");
}
#eliif DS==2
void main(){
printf("hello DS==2");
}
#endif
#endif // TEST1_H_INCLUDED
오류는
**> E입니다 함수 'main': |
E:\Documents\Myprojects\My C PRoj\Te\test1.c|8|warning: implicit declaration of function 'm'| obj\Debug\test1.o||In function `main':| E:\Documents\Myprojects\My C PRoj\Te\test1.c|8|undefined reference to `m'| ||=== Build finished: 1 errors, 1 warnings ===|**
단순히 다음 코드와 함께 컴파일 조건 매크로를 제거하는 경우 :
파일 ::::: test1.c
#include<stdio.h>
#include "test1.h"
int main(){
m();
return 0;
}
파일 ::::: test1.h
#ifndef TEST1_H_INCLUDED
#define TEST1_H_INCLUDED
void m(){
printf("uncoditional macro");
}
#endif // TEST1_H_INCLUDED
모든 것은 잘 작동합니다. 이유가 무엇입니까?
* 당신 생각은 어떨까요? – Elazar
당신은 무엇을 이해하지 못합니까? – nouney
[(i = i ++ + ++ i, i = i ++, etc ...) 이러한 정의되지 않은 동작을 설명 할 수 있습니까?] (http://stackoverflow.com/questions/949433/could-anyone-explain-these -undefined-behaviors-iiiii-etc) –