Fix cmake C++ template compilation and linking