I hope this thread is appropriate for this forum.
I recently began using the visibility attribute now available in gcc.
The software I am working on is proprietary (my employer pays the bills ;) ). We have several modules, each built as a separate DSO library. One of these has a large template class with several specialized methods. We do not provide the implementations on the header file, so this means we limit our users to only those template instances that we explicitly instantiate in the implementation file.
I cannot seem to get this template class working with g++ and its visibility attribute. Below is much simplified example that demonstrates my problem. Environment is Ubuntu Dapper, g++ version 4.0.3, kernel version 2.6.15-27-686.
Error message:
----------------------
/tmp/ccsVuuf1.o: In function `main':TestMain.cpp:(.text+0x33): undefined reference to `TestClass::test(double const&) const' collect2: ld returned 1 exit status
Build commands:
------------------------
g++ -c -O3 -fpic -fvisibility=hidden -fvisibility-inlines-hidden -std=c++98 -pedantic TestClass.cpp g++ -shared -o libTestClass.so TestClass.o g++ -o TestMain TestMain.cpp -L. -lTestClass
TestClass.hpp:
---------------------
#ifndef HPP_TESTCLASS
#define HPP_TESTCLASS
template
class __attribute__ ((visibility("default"))) TestClass
{
public:
bool test(_Tp const& x) const;
};
#endif
TestClass.cpp:
---------------------
#include "TestClass.hpp"
#include
template
bool
TestClass<_Tp>::
test(_Tp const& x) const
{ return typeid(x) == typeid(_Tp); }
template class __attribute__ ((visibility("default"))) TestClass;
TestMain.cpp:
-------------------
#include "TestClass.hpp"
int main()
{
TestClass t;
t.test();
return 0;
}
Thanks in advance for any insight that you can provide.
-Matthew-
templates and visibility mix
templates and visibility mix since g++ 4.1 only. you should upgrade. this is a bug in gcc < 4.1. at least if i understood your problem
I have gcc 4.1 on a non-work
I have gcc 4.1 on a non-work platform. I will try it out. Thanks for the advice; if that's it then at least I might have a workaround.
-Matthew-