nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

g++: using visibility attrib w/ explicit template instances

This is a discussion on g++: using visibility attrib w/ explicit template instances within the Coding in General forums, part of the Development/Scripting category; I hope this thread is appropriate for this forum. I recently began using the visibility attribute now available in gcc. ...


Go Back   nixCraft Linux Forum > Development/Scripting > Coding in General

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 10-16-2006, 10:20 PM
Junior Member
 
Join Date: Oct 2006
Location: Hudson Valley, NY
Posts: 2
Rep Power: 0
Q.E.D.
Default g++: using visibility attrib w/ explicit template instances

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:
----------------------
Code:
/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:
------------------------
Code:
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:
---------------------
Code:
#ifndef HPP_TESTCLASS
#define HPP_TESTCLASS

template
class __attribute__ ((visibility("default"))) TestClass
{
public:
    bool test(_Tp const& x) const;
};
#endif
TestClass.cpp:
---------------------
Code:
#include "TestClass.hpp"
#include

template
bool
TestClass::
test(_Tp const& x) const
{ return typeid(x) == typeid(_Tp); }

template class __attribute__ ((visibility("default"))) TestClass;
TestMain.cpp:
-------------------
Code:
#include "TestClass.hpp"

int main()
{
    TestClass t;
    t.test();
    return 0;
}
Thanks in advance for any insight that you can provide.

-Matthew-
Reply With Quote
Sponsored Links
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +5.5. The time now is 05:49 AM.


Powered by vBulletin® Version 3.7.3 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36