正如标题所说,我一直得到一个未定义的错误引用,但我不知道为什么…
我有一个主例程,其中包含了我想要使用的函数的头,因此包含在定义函数的cpp文件中。我还包含了项目设置
的路径我知道我应该张贴代码,但我不允许这样做,但仍然希望我能得到一些提示解决这个错误。
Thanks in advance
UART_write(UARTvar, LVL); //This is where I call the function
int UART_write(int uart, const char* var);//Declaration in the header
int UART_write(int uart, const char* var)
{
return (int)1;//just for testing
}
对' UART_write'的未定义引用
如果您有以下项目结构:
header.h:
#ifndef _HEADER_H_
#define _HEADER_H_
int UART_write(int uart, const char* var);
#endif
c:
#include "header.h"
int main()
{
...
UART_write(UARTvar, LVL);
...
}
所以请确保你没有在任何其他地方定义_HEADER_H_
,因为在这种情况下,UART_write()
原型将不包括在构建中。
还请检查UART_write()
原型是否没有放在#if
或#ifdef
和#endif
预处理器命令之间。
最后一个,你可以通过在标题中的UART_write()
原型之前添加#error "This code is compiled"
来检查上面的内容。如果这部分代码被编译,那么你会得到编译错误This code is compiled
.