473,803 Members | 3,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

template instance in shared library on sun 5.7

Hello,

I have a templated class defined in a header file and implemented in a
cpp
source file. The class is basically a little marshaler that contains a
factory method and a few marshaling functions. The template parameter
defines the type stored in a contained vector. That class is built into
a
shared library. The (condensed) code goes like this...

TypeMarshaler.h

#include <vector>
#include <string>

struct ITypeMarshaler
{
virtual void Marshal() = 0;
virtual void Unmarshal() = 0;
};

template <typename T>
class TypeMarshaler : public ITypeMarshaler
{
public:
virtual void Marshal();
virtual void Unmarshal();

private:
std::vector<T> dataValues;
};

class TypeMarshalerFa ctory
{
public:
static ITypeMarshaler* Create(const std::string &dataType);
};

TypeMarshaler.c pp

#include "TypeMarshaler. h"

ITypeMarshaler* TypeMarshalerFa ctory::Create(c onst std::string
&dataType)
{
// this is implemented using a map in the real code, but just so you
get
the idea...
if(dataType == "System.Int 32") { return new TypeMarshaler<l ong>; }
... and so on
}

template <typename T>
void TypeMarshaler<T >::Marshal()
{
...
}

template <typename T>
void TypeMarshaler<T >::Unmarshal( )
{
...
}

The client code looks like this and links against the shared library...

Client.cpp

#include "TypeMarshaler. h"

int main()
{
ITypeMarshaler *tm = TypeMarshalerFa ctory::Create(" System.Int32");

... use tm & do other stuff.

return 0;
}

The client does what I expect on HP-UX 11 using aCC, Linux using gcc,
Windows using MS VC 6 & 7. However, on Sun 5.7 using whatever the most
popular Sun-supplied compiler is, linking the client results in
unresolved
externals of the form...

std::vector<lon g, allocator_stuff <long> >::_M_fill_inse rt(...) first
referenced in libTypeMarshale r.so.

I would have thought that having the TypeMarshalerFa ctory::Create()
method
reference a data type in a "new" expression would have been good enough
to
get the contained vector type defined in the shared library, since
client
code doesn't directly reference the TypeMarshaler type.

Am I doing something fundamentally wrong?

Thanks,
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]
Jul 19 '05 #1
1 2403
On 8 Jul 2003 00:30:04 -0400, "John Dumais" <no***********@ sonic.net>
wrote:
The client does what I expect on HP-UX 11 using aCC, Linux using gcc,
Windows using MS VC 6 & 7. However, on Sun 5.7 using whatever the most
popular Sun-supplied compiler is, linking the client results in
unresolved
externals of the form...

std::vector<lo ng, allocator_stuff <long> >::_M_fill_inse rt(...) first
referenced in libTypeMarshale r.so.


You should ask in a sun newsgroup, since this is obviously a sun
specific problem. (hint -

-xar Creates archive libraries.

When building a C++ archive that uses templates,
it is necessary in most cases to include in the
archive those template functions that are instan-
tiated in the template repository. Using this
option automatically adds those templates to the
archive as needed.

Examples:

The following command archives the template func-
tions contained in the repository and the object
files.

% CC -xar -o libmain.a a.o b.o c.o

Warnings:

Do not add .o files from the template repository
on the command line.

Do not use the ar command directly for building
archives. Use CC -xar to ensure that template
instantiations are automatically included in the
archive.

)

Tom

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
12824
by: zhou | last post by:
Hi there, We have a compiler specific issue which requires us to force template instantiation. This works fine. The problem comes when I try using std:find() on vector. Since vector has no member function find() and I have to use std::find(). The linker fails on unsatisified symbols in find(). I think this is because find() is a template function and I have to force instantiation. However, I donot know the correct syntax of doing so....
7
12481
by: Tim Clacy | last post by:
Is there such a thing as a Singleton template that actually saves programming effort? Is it possible to actually use a template to make an arbitrary class a singleton without having to: a) explicitly make the arbitrary class's constructor and destructor private b) declare the Singleton a friend of the arbitrary class
4
3139
by: Graham Dumpleton | last post by:
When you have a template class with a static member variable, ie., template<typename T> class handle { public: static void* id() { return &id_; } private: static int id_; };
7
3590
by: Paul | last post by:
Hi, I have a problem with the C++ spec 14.7.3.15 (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14761 for relevant discussion). It seems that the code (below) is impossible to get right, as you cannot define a static data member of a template class if it ONLY has a default-initializer...
1
2300
by: Frederiek | last post by:
Hi, When modifying a data member in a class declaration, the static keyword specifies that one copy of the member is shared by all instances of the class. Does that mean that the address of the data member is the same for every instance of that class? I would expect so, but I noticed something that makes me doubt a little.
8
2146
by: Ole Nielsby | last post by:
I want to create (with new) and delete a forward declared class. (I'll call them Zorgs here - the real-life Zorks are platform-dependent objects (mutexes, timestamps etc.) used by a cross-platform scripting engine. When the scripting engine is embedded in an application, a platform-specific support library is linked in.) My first attempt goes here: ---code begin (library)---
13
6601
by: mike b | last post by:
Hello everyone, thanks in advance for your help. I'm new to C++ templates and have run into some issues using member function templates. I have a shared library containing templates that I'm trying to use from an executable, compile using gcc 4.1.2. Everything works fine until I try specializing one of the static member function templates in a non-template class. I have a feeling I'm messing up something obvious so before I post a...
32
2746
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template issue. A noddy mixin layer example should illustrate the issue... class Base { protected: int m_Field;
45
3024
by: =?Utf-8?B?QmV0aA==?= | last post by:
Hello. I'm trying to find another way to share an instance of an object with other classes. I started by passing the instance to the other class's constructor, like this: Friend Class clsData Private m_objSQLClient As clsSQLClient Private m_objUsers As clsUsers
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.