cmds.cpp有这个:
namespace TestNamespace
{
template<typename... Args>
void tprint(Args const& ... args)
{
std::ostringstream message;
using List= int[];
(void)List{0, ((void)(message << args), 0) ... };
std::cout << message.str();
}
}
cmds.h有这个:
namespace TestNamespace
{
template<typename... Args> void tprint(Args const& ... args);
}
main.cpp有这个:
#include "cmds.h"
using namespace TestNamespace;
void func()
{
tprint("test\n");
}
编译器愉快地编译。然而,Linker说:
main.cpp: undefined reference to `void TestNamespace::tprint<char [6]>(char const (&) [6])'
collect2: error: ld returned 1 exit status
Makefile标志:
CPPFLAGS=-std=c++11 -m32 -Wall -g -I./ -Wno-trigraphs
LDFLAGS=-std=c++11 -m32 -L./ -lm
发生了什么事?