g++ main.c f.c
below works with g++-4.2.1, but
g++ -O3 main.c f.c
gives the warning
/usr/libexec/gcc/powerpc-apple-darwin8/4.2.1/ld: Undefined symbols:
int f<int>(int const*)
collect2: ld returned 1 exit status
// main.c
template <typename T>
int f( const T* A );
int main()
{
int* A = new int[10];
int ftemplate = f( A );
}
// f.c
template <typename T>
int f( const T* A )
{ return A[0];
}
int call_f()
{ int* A = new int[10];
return f( A ); // ok here but not from main()
}
On macosx 10.4.11 powerpc-apple-darwin8-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5564),
-O2
works, -O3
does not.
On macosx 10.7.4 i686-apple-darwin11-llvm-g++-4.2
(from https://github.com/kennethreitz/osx-gcc-installer),
plain g++ *.c
works, g++ -O *.c
gives the same ld: Undefined symbols
error.
Maybe a bug g++ <-> old /usr/bin/ld ? More likely I've done something stupid ...
Can anyone help, or see if this works on a non-Mac ? Thanks !