问题描述
我收到以下错误:
features.cpp:(.text+0x4f6): undefined reference to `void Convolve<float>(CImageOf<float>, CImageOf<float>&, CImageOf<float>)'
所以,在我的features.cpp文件中,我添加了以下头文件,内容:
So, in my features.cpp file, I added the following header file, with the content:
template <class T>
void Convolve(CImageOf<T> src, CImageOf<T>& dst,
CFloatImage kernel);
我在ubuntu 64位上用GCC编译。我意识到,上面的错误是因为我的标题不匹配的引用,但这是因为模板,所以我不应该有这个问题吗?还有什么事吗?
I'm compiling this with GCC on ubuntu 64bit. I realize that the error above is because what is in my header does not match the reference, but that's because of the template, and so I shouldnt be having this problem right? What else is going on?
我双重检查了我对convolve的调用,实际上是我使用的类型:
I double checked my calls to convolve, and actually this is the types I'm using :
Convolve(CFloatImage, CFloatImage, CFloatImage);
我实际上找不到上述错误的任何参考
I can't actually find any reference to the error above
推荐答案
在与OP问题可能在一个Makefile没有正确链接。
As turned out in a chat with the OP the problem was probably in a Makefile that did not link correctly.
没有定义,但模板的声明。 h文件(因为你建议的一些)。我认为OP混淆了这些术语。
There was no definition but a declaration of the template in the .h file (as some of you suggested). I think the OP confused the terms.
然而,.cpp文件中有一个模板定义以及一个(非模板)函数定义实例化 Convolve< float>
(和其他人)。
However there was a definition of the template in the .cpp file along with a (non template) function definition that instantiated Convolve<float>
(and others).
所以重复一遍:代码是正确的,但是构建例程不是。
So to repeat it: The code was correct but the build routine was not.
这篇关于未定义对void“函数”的引用。 C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!