c - 包含文件似乎被忽略

标签 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

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

例如,

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

我错过了什么?

最佳答案

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

关于c - 包含文件似乎被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51641861/

相关文章:

c - C中的计时器实现,用于在计时器到期后删除链表中的记录

c++ - 是否可以在编译时收集数据

c - 拒绝指针的数组大小的宏

C 数组/指针声明语法测验

c: 读入 int 不完整

c - 右移 signed int 是否为 8 * sizeof(int) 或更多未定义?

模拟默认定义的条件宏定义

c++ - C++ 编译器何时会为方法推断出 noexcept?

c - sizeof 函数在外部数组上一直失败

c - GNU 内联汇编程序——汇编指令的语法?