“未定义的对功能的引用”错误 [英] "Undefined reference to function" error
问题描述
我在使用标头编译几个文件时遇到了一些问题。以下是我的代码明细:
file1.c
#includeheader.h
int main(){
func1();
return 0;
}
file2.c
$ b
#includeheader.h
void func1(){
...函数实现...
}
header.h
void func1();
我得到的错误是:
在函数
'main'
:
未定义引用'func1'
注意:我只是使用我的3个文件。我需要得到这个工作与3个文件。我正确设置/包括一切?我需要使用这个设置,但我只是不确定如何file.c参考实际的实现 func1()
。
如果错误是未定义的引用 func1()
, ,那么我认为这是因为您的项目中有两个名为 header.h
的文件,而其中包含了另一个副本,而不是您的副本 func1()
。
我将检查您的项目的包含路径,并确保
header.h
,其中包含您的声明 func1()
。 I am having some trouble compiling a few files using headers. Here is a breakdown of my code:
file1.c
#include "header.h"
int main() {
func1();
return 0;
}
file2.c
#include "header.h"
void func1() {
... function implementation ...
}
header.h
void func1();
The error I am getting is:
In function
'main'
:
undefined reference to'func1'
Note: I am just using a simple breakdown of how my 3 files are set up. I need to get this to work with the 3 files. I am setting/including everything properly? I need to use this set up, but I am just unsure how file.c gets reference to the actually implementation of func1()
.
If the error is an undefined reference to func1()
, and there is no other error, then I would think it's because you have two files called header.h
in your project and the other copy is being included instead of your copy with the declaration of func1()
.
I would check the include paths for your project and make sure that the header.h
with your declaration of func1()
is being included first.
这篇关于“未定义的对功能的引用”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!