So in C++ the following compiles:
// foo.hpp
template <typename T> T foo(T bar);
// foo.cpp
#include "foo.hpp"
template <typename T> T foo(T bar)
{
bar++;
return bar;
}
template char foo(char bar);
// main.cpp
#include "foo.hpp"
extern template char foo(char bar);
char Cplusplus()
{
return foo('C');
}
int main() {}
If I copy all code except main() into a Metal shader library with foo.hpp, foo.metal and main.metal and try to compile, then at the linking step I get the following:
metallib: multiple symbols ('_Z3fooIcET_S0_') with incompatible linkages!
Is there any way to use templates in Metal that doesn't involve any code duplication? (i.e. defining templates in headers, trivial specializations, etc)