On Apr 9, 2007, at 6:49 AM, Chris Dams wrote:
I am not sure whether the problem I am going to describe is a problem with gcc or with the dynamic linker on Mac OS X, but maybe someone here knows a way to deal with it or could suggest a more appropriate mailing list. I
use gcc 3.3 on Darwin 7.9.0.

The nicest way to fix this would be to update the OS and the compiler. The second best way might be to do:

mrs $ g++-3.3 -c -o test.o test.C; g++-3.3 -c -o main.o main.C; g ++-3.3 -dynamiclib -o test.dylib test.o; g++-3.3 -o main main.o test.dylib
mrs $ ./main
the address of v is 929800
the address of v is 929800
mrs $ cat test.h#include <iostream>
#include <vector>

template <class T> class test
{   public:
        test()
{ std::cout << "the address of v is " << (int)&v << std::endl;
        }
        void method() {}
    private:
        static std::vector<T> v;
};

template <class T> std::vector<T> test<T>::v;
extern template test<int>;

extern test<int> t;
mrs $ cat test.C
#include "test.h"

test<int> t;
template test<int>;
mrs $ cat main.C
#include "test.h"

int main()
{       t.method();
        test<int> t2;
        return 0;
}

or any other technology that can handle templates being duplicated across dynamic library boundaries.

Reply via email to