[Insight-developers] templates on osx (using -frepo)
Yarden Livnat
yarden@cs.utah.edu
Fri, 22 Nov 2002 11:08:59 -0700
Hi,
I ran across a c++ template problem on OSX. After playing with it
for a while I was able to reduce it to the following:
=== the code ==
template<class T> class Base {
public:
Base() {}
void test();
void test2() { return; }
};
template<class T>
void Base<T>::test() {return;}
int main()
{
Base<int> b;
b.test2();
b.test();
return 1;
}
== ok compilation ===
> c++ -c main.cc
> c++ -o main main.cc
>
i.e. linked fine.
=== bad linkng ====
> c++ -frepo -c main.cc
> c++ -frepo -o main main.cc
ld: Undefined symbols:
Base<int>::test()
the same code with the same compilation flags works on linux gcc-3.04
=== a solution ==
of cause, I could explicitly instantiate
void Base<int>::test() { return; }
and this does work.
=== but...===
the problem is that this happens when I use the STL (i.e. the
internal _M_insert_...
and other similar protected methods are not instantiated ).
I would have refrained from using "-frepo" but this cause a lot of
extra code to be
generated as well as causing some other errors (multiple defined
errors) in other
places in our, somewhat large, code.
Any help will be greatly appreciated.
Yarden Livnat
SCI Institute
University of Utah