【发布时间】:2012-02-01 04:04:31
【问题描述】:
我有radius2 = x*x +y*y + z*z。
我想在不删除 z*z 的情况下将 3D 切换到 2D(即radius2 = x*x + y*y)。
我试图定义一个宏
1.h [2D/3D切换头文件]
#define DIMENSIONS 2 //or, 3
2.h
#if DIMENSIONS == 2
#define EXPAND(a,b,c) a, b
#endif
#if DIMENSIONS == 3
#define EXPAND(a,b,c) a, b, c
#endif
main.c
#include "stdio.h"
#include "1.h"
#include "2.h"
main(){
int x, y, z, radius2;
x = 2;
y = 3;
z = 4;
radius2 = EXPAND(x*x, +y*y, +z*z);
printf("%d", radius2);
}
编译时出现此错误:
Undefined symbols:
"_EXPAND", referenced from:
_main in ccsC4tfr.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
【问题讨论】:
标签: c macros compiler-errors