c++使用模板 new时提示undefined reference
#ifndef _POOR_H_
#define _POOR_H_
using namespace std;
//池
template<class D>
class Poor
{
public:
Poor();
~Poor();
};
#endif
poor.cpp
#include "poor.h"
template<class D>
Poor<D>::Poor()
{
}
template<class D>
Poor<D>::~Poor()
{
}
typedef struct
{
int key;
char value[20];
} stParseMap;
int main (int argc,char *argv[])
{
Poor<stParseMap> *b = new Poor<stParseMap>();//该行编译报错
return 0;
}
makefile:
#!/bin/ksh
IFLAGS=-DSS_64BIT_SERVER -D_REENTRANT -D_DSCI_ -D_THREAD_LOG_ -D_DEBUG_INFO_ -D_TIME_LOG_
INCLUDE=-I.
LIB=-L.
.SUFFIXES:.cpp .o
CFLAGS = ${IFLAGS} ${INCLUDE}
CC=g++ -m64 -g -O2 -fpermissive
OBJ = ibeartest.o poor.o
BIN=ibeartest
all:${BIN} install clean
.cpp.o:
echo "Compiling the $<"
$(CC) -c ${CFLAGS} $<
.c.o:
echo "Compiling the $<"
$(CC) -c ${CFLAGS} $<
clean:
rm -f ibeartest.o poor.o
######################################################################
${BIN}: $(OBJ)
$(CC) ${CFLAGS} -o $@ $? ${LIB}
######################################################################
install:
程序在hp-hx acc上编译可以通过~
移植到linux g++ 编译时报错:
make -f makefile
g++ -m64 -g -O2 -fpermissive -DSS_64BIT_SERVER -D_REENTRANT -D_DSCI_ -D_THREAD_LOG_ -D_DEBUG_INFO_ -D_TIME_LOG_ -I. -o ibeartest ibeartest.o poor.o -L.
ibeartest.o: In function `main':
/ocsapp/account/work/wangzhia/cc/ibeartest.cpp:24: undefined reference to `Poor<stParseMap>::Poor()'
collect2: ld 返回 1
make: *** [ibeartest] 错误 1
相关推荐
C生成静态库给C++调用出现undefined reference to ...解决方案_cpp
在C++程序中调用C编译的静态库时,可能会遇到“undefined reference to ...”错误,这通常意味着链接器无法找到对应的函数定义。
C++模板链接错误:undefined reference to的根源与解决方案
C++的分离编译模型是理解程序构建过程的基础概念,它规定了编译器独立处理每个源文件生成目标文件,再由链接器解析符号引用。对于普通函数,声明与定义分离是标准实践,但模板机制打破了这一常规——编译器需要看到模板的完整定义才能为特定类型生成实例化代码。这一特性在工程实践中至关重要,直接关系到代码的组织方式与构建效率。当模板成员函数定义与声明分离在不同文件时,就会引发经典的undefined reference to链接错误,这正是C++模板编程中的常见陷阱。本文聚焦于类模板的链接问题,通过剖析编译单元与实例化时机
undefined reference to `SetPduPowerConsumptionCnt'错误的解决方法
在这个特定的问题中,开发者在C++项目中遇到了“undefined reference to `SetPduPowerConsumptionCnt'”的错误。该错误通常出现在以下几种情况:1.
undefined reference to 'pthread_create'的解决方法
在编程过程中,尤其是在使用多线程技术时,可能会遇到“undefined reference to 'pthread_create'”这样的链接错误。
undefined reference to `SetPduPowerConsumptionCnt’错误的解决方法
在编程过程中,遇到“undefined reference to `SetPduPowerConsumptionCnt’”这样的错误,通常意味着链接阶段找不到该函数的定义。


