開發平台(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
請問這是什麼原因造成?
謝謝