473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 TypeMarshalerFactory
{
public:
static ITypeMarshaler* Create(const std::string &dataType);
};

TypeMarshaler.cpp

#include "TypeMarshaler.h"

ITypeMarshaler* TypeMarshalerFactory::Create(const std::string
&dataType)
{
// this is implemented using a map in the real code, but just so you
get
the idea...
if(dataType == "System.Int32") { return new TypeMarshaler<long>; }
... 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 = TypeMarshalerFactory::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<long, allocator_stuff<long> >::_M_fill_insert(...) first
referenced in libTypeMarshaler.so.

I would have thought that having the TypeMarshalerFactory::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++.moderated. First time posters: Do this! ]
Jul 19 '05 #1
1 2373
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<long, allocator_stuff<long> >::_M_fill_insert(...) first
referenced in libTypeMarshaler.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++.moderated. 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
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...
7
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)...
4
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
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...
1
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...
8
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...
13
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...
32
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...
45
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.