Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22148

OSX clang++: Undefined symbols for architecture x86_64 for explicitely instantiated template in cpp file

$
0
0

I have template class defined in .h file and template methods are defined in .cpp file. This .cpp file also contains explicit template instantiation via template clas Class<type>.

This use case works correctly on VS2019 as same as on GCC (7.4.0). But, it's not working on OSX with clang++ (Apple LLVM version 10.0.0 clang-1000.11.45.5).

Based on the documentation I believe this is a valid code. Is there any way how to make it work under OSX clang?

I don't want to move all implementations to .h because of better readability and because I need only two/three template instantiations.

Here are my test files:

test.h

#pragma oncetemplate <class T>class CTemplateTest{public:  int Test();};

test.cpp

#include "test.h"template class CTemplateTest<int>;template class CTemplateTest<double>;template <class T>int CTemplateTest<T>::Test(){    return 42;}

main.cpp

#include "test.h"int main(int argc, char** argv){    CTemplateTest<int> t1;    CTemplateTest<double> t2;    t1.Test();    t2.Test();}

output

Undefined symbols for architecture x86_64:"CTemplateTest<double>::Test()", referenced from:      _main in main.o"CTemplateTest<int>::Test()", referenced from:      _main in main.old: symbol(s) not found for architecture x86_64

Thanks for any help.


Viewing all articles
Browse latest Browse all 22148

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>