作者tinlans ( )
看板Programming
标题Re: [问题] undefined reference to ..
时间Wed Apr 4 12:36:26 2007
※ 引述《kornelius (Kornelius)》之铭言:
: 我在 hashmap.h 内定义
: 然後在 hashmap.cpp 内实做
: 主程式写在 hashtest2.cpp
: 然後编译,却出现这样的 bug ,一直想不透是什麽问题...搞了好久啊啊啊 Orz
: 也检查过,也没有忘了实做的函数
: $ g++ hashtest2.cpp hashmap.cpp -o test
: /tmp/ccKWvjRU.o: In function `main':
: hashtest2.cpp:(.text+0x9a): undefined reference to `HashMap<int,
: int>::HashMap()'
: hashtest2.cpp:(.text+0xbb): undefined reference to `HashMap<int,
: int>::add(int, int)'
: hashtest2.cpp:(.text+0xd6): undefined reference to `HashMap<int,
: hashtest2.cpp:(.text+0x22b): undefined reference to `HashMap<int,
: int>::~HashMap()'
关於这个你必须要在 .cpp 内的 template 定义式之前加上 export,
不过 g++ 没有支援 export 这个功能,
所以你必须把 template 定义在 header file 内。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.230.224.23
1F:推 kornelius:谢谢 59.116.170.218 04/04 21:11