开发平台(Platform): (Ex: VC++, GCC, Linux, ...)
Linux/g++
// 将 template 宣告在 quaternion.h , 函数实作在 quaternion.cpp
https://gist.github.com/anonymous/00090f1598973c1c924afebf88199cc9
这样编译下面错误
g++ main.cpp quaternion.cpp -o main
/tmp/ccnOQeym.o: In function `main':
main.cpp:(.text+0x27): undefined reference to
`Quaternion<float>::Quaternion()'
main.cpp:(.text+0x38): undefined reference to
`Quaternion<float>::~Quaternion()'
collect2: error: ld returned 1 exit status
我把template 宣告跟实做都集中在 quaternion.h 可以编译过
https://gist.github.com/anonymous/21a12dfedf6982b963d249f890977aaf
g++ main.cpp -o main
请问这是什么原因造成?
谢谢