[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::c_plus_plus

Title:C++
Notice:Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS)
Moderator:DECCXX::AMARTIN
Created:Fri Nov 06 1987
Last Modified:Thu Jun 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3604
Total number of notes:18242

3416.0. "possible to create .so using templates in 3.2?" by KZIN::HUDSON (That's what I think) Thu Jan 30 1997 12:39

I have a case where I want to create a shared object from a file that is
auto-instantiating a template class.  This appears to complicate the
link process somewhat, and although I haven't tried exhaustively, I'm
getting the feeling that it may not be possible to engineer a set of
commands that will cause this to be built properly.

Specifically, I want to be able to do the following

cxx -shared -I./template useit.cxx -o useit.so

The line above gives me the "see release notes" warning from the compiler,
and "must specify one of..." error from the linker.  So I do the compile
and link separately, and then get a "unresolved symbol" for my template
constructor.

I guess this means I need to use "cxx" as my link driver, so that my
template will get instantated at link time, but if I do that then I'm back
to the problem of "-call_shared".

Is there a way round this?

Thanks for any help,
nick
<files follow>
------------------------------------------------------
// useit.cxx
#include "mytemplate.h"
int func1()
{
	int	x = 1;

	mytemplate<int>	instance(x);

	return x;
}
------------------------------------------------------
// mytemplate.h
#ifndef __MYTEMPLATE_H
#define __MYTEMPLATE_H

template<class T> class mytemplate {
	T	item;
public:
	mytemplate(T&);
};

#endif
------------------------------------------------------
// mytemplate.cxx
#include "mytemplate.h"

template<class T>
mytemplate<T>::mytemplate(T &param)
{
	item = param;
}



T.RTitleUserPersonal
Name
DateLines
3416.1how about this...DECC::J_WARDThu Jan 30 1997 12:4012
Try using -Hf on the cxx compile line
and explicitly link in cxx_repository/*.o
on the ld line, i.e.:

cxx -I./template -Hf useit.cxx

ld -o useit.so -g0 -O1 -shared /usr/lib/cmplrs/cxx/_main.o ./cxx_repository/*.o
useit.o -lcxxstd -lcxx -lexc -lc

This is sort of the technique we use when
we need to create common instantiaton libraries.
3416.2DECC::FOLTANThu Jan 30 1997 12:4615
3416.3oops, my faultKZIN::HUDSONThat's what I thinkThu Jan 30 1997 12:4730
re: .0

Sorry; I've just re-read the release notes and found that this is possible.

Specifically, in case other people come across this, the way I got the
code in .0 to compile was:

% cxx -I./template -o useit.o -c useit.cxx
% cxx -v -call_shared -o useit.so useit.o
.
.
.
/usr/lib/cmplrs/cc/ld -o useit.so -L/usr/lib/cmplrs/cxx -rpath /usr/lib/cmplrs/c
xx -g0 -O1 -call_shared /usr/lib/cmplrs/cc/crt0.o /usr/lib/cmplrs/cxx/_main.o ./
cxx_repository/mytemplate__Ti.o useit.o -lcxxstd -lcxx -lexc -lots -lc
ld:
Unresolved:
main
.
.
.
(use the last "ld" line displayed but modify it to:)
% ld -o useit.so -L/usr/lib/cmplrs/cxx -rpath /usr/lib/cmplrs/cxx -g0 -O1 -share
d /usr/lib/cmplrs/cc/crt0.o /usr/lib/cmplrs/cxx/_main.o ./cxx_repository/mytempl
ate__Ti.o useit.o -lcxxstd -lcxx -lexc -lots -lc -expect_unresolved main


[Moderators, please feel free to delete this note/reply if you want...]

nick
3416.4KZIN::HUDSONThat's what I thinkThu Jan 30 1997 12:488
re: .1 .2

You got those in while I was typing .3

Thanks very much, I'll have a play with Hf, this could be more elegant
than the solution in .3 for my customer who has a much larger app.

nick