poor.h代码:
#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
解决方案
40
#include “poor.cpp”