我目前正在使用 keil 编译器编写 C 代码。我面临一个问题,我必须使用内联函数(在我的情况下性能很重要,所以我必须使用它)并且我有一个包含内联函数的文件。这个内联函数在头文件中声明,我尝试从另一个包含头文件的文件访问。我总是得到:调用函数时出现 undefined symbol 错误...
这是说明我的问题的例子:
文件:测试.h
extern void my_function (void);
文件:test.c
#include "test.h"
__inline void my_function (void)
{
printf("test ok\r\n");
}
文件:main.c
#include "test.h"
int main (void)
{
my_function ();
}
==> 链接错误: undefined symbol my_function
我可以改用宏,但您知道解决我的问题的其他方法吗?
最佳答案
您可以在头文件中定义内联函数:
File : test.h
static inline void my_function (void)
{
printf("test ok\r\n");
}
关于c - 从另一个文件访问内联函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19162732/