c - 从另一个文件访问内联函数

标签 c keil

我目前正在使用 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/

相关文章:

C - 访问哈希表中的结构成员时出现段错误(插入函数)

c - 如何在c中声明单链表?

c - 为什么编译器把C程序汇编成这个?

c - array [] vs pointer * - 为什么第一个代码在 C 中会失败?

c# - 托管线程会影响 C dll 中的全局变量吗?

c - 绑定(bind) UDP 套接字时出现问题

c++ - 如何通过 c_str() 库 API 使用 C++ 流。

c - 在 Micro 8051 的 Keil 中将字符指针函数的返回值分配给字符变量数组时出错

embedded - 尝试调试STM32F205ZG时出现"Could not stop Cortex-M device"错误

c - 在 Visual Studio 2012 中包含头文件