包含文件似乎被忽略

时间:2018-08-01 20:33:42

标签: c gcc c-preprocessor

我确定看不到明显的东西,但这是:

我写了一个很小的tools.h文件,其中包含2个宏,这些宏在项目的多个文件中使用:

#ifndef _TOOLS_H_
#define _TOOLS_H_


#define is_in_range(x, a, b) ((x) >= (a)) && ((x) < (b))

#define clamp(x, a, b)\
    (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))

#endif

我在每个源文件中使用#include "tools.h"clamp添加了is_in_range,但是在编译时似乎忽略了它们。

例如,

C:/SGDK134/bin/gcc -m68000 -Wall -fno-builtin -Iinc -Isrc -Ires -IC:/SGDK134/inc -IC:/SGDK134/res -BC:/SGDK134/bin -O3 -fuse-linker-plugin -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer -flto -c src/camera.c -o out/src/camera.o
src/camera.c: In function 'camera_set_focus':
src/camera.c:130:6: warning: implicit declaration of function 'clamp' [-Wimplicit-function-declaration]
 x = clamp(fix32ToInt(obj->x) - 128, 0, current_stage.pwidth - 320);

我还有其他几个,每个源文件一个,引用了tools.h

当然,编译会中止:

C:/SGDK134/bin/gcc -BC:/SGDK134/bin -n -T C:/SGDK134/md.ld -nostdlib out/sega.o @out/cmd_ C:/SGDK134/lib/libmd.a C:/SGDK134/lib/libgcc.a -o out/rom.out
C:\Users\xxxx\AppData\Local\Temp\cczl66At.ltrans0.ltrans.o: In function `main':
.text.startup+0x3ec): undefined reference to `clamp'
.text.startup+0x972): undefined reference to `clamp'
.text.startup+0x9c8): undefined reference to `clamp'
.text.startup+0xb5c): undefined reference to `is_in_range'
.text.startup+0xce0): undefined reference to `clamp'
make.exe": *** [out/rom.out] Error 1

我想念什么?

1 个答案:

答案 0 :(得分:2)

答案是由user3386109给出的:我正在使用的库中有一个名为tools.h的文件。

相关问题