c++ 中目录中文件的未定义引用错误
An undefined reference error for files in a directory in c++
我正在做一个项目,在项目内部,我将自己的类和函数分离到一个名为base_lib的目录中。编译项目时,我不断收到此库中某个类的未定义引用错误。我一直试图在许多不同的论坛上找到答案,最终决定自己问。代码:
堆栈.h
#ifndef __STACK_H
#define __STACK_H
namespace stacker
{
/*******
My code here
*******/
}
#endif
堆栈.cpp
#include "stack.h"
#include <iostream>
using namespace std;
template <typename var>
stacker::Stack<var>::Stack()
{
head = nullptr;
tail = nullptr;
}
修复.h
#ifndef __FIX_H
#define __FIX_H
#include <iostream>
#include <string>
namespace fixes
{
/*******
My code here
*******/
}
#endif
修复.cpp
#include "fix.h"
#include "base_lib/stack.h"
#include <iostream>
#include <string>
using namespace std;
using namespace stacker;
主.cpp
#include <iostream>
#include "fix.h"
#include "base_lib/functions.h"
using namespace fixes;
using namespace mine;
using namespace std;
编译器错误
C:...:fix.cpp:(.text+0xa2): undefined reference to `stacker::Stack<char>::Stack()'
...
有人有任何提示或技巧吗?
您似乎在C++文件中有一个模板,而不是头文件。
这意味着模板将无法编译,因此您会收到错误。
在这里阅读:为什么模板只能在头文件中实现?
相关文章:
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 对 Scalar ::Scalar() 的未定义引用
- 对复制 CTOR 和 CTOR 的未定义引用
- 对显式实例化的模板函数的未定义引用
- TensorRT (C++ API) 对"createNvOnnxParser_INTERNAL"的未定义引用
- 2个模板化类的非模板友元函数未定义引用错误
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 获取对function_name的未定义引用
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- 对结构方法的未定义引用
- 使用内联函数 c++ 的未定义引用
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 对 DLOPEN 的未定义引用
- QT C++中对全局变量的未定义引用
- 快速数学导致对"__pow_finite"的未定义引用
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用