473,386 Members | 1,668 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,386 software developers and data experts.

Simple question about templates

Hello,
I have a class with a number of functions like this one.

typedef unsigned char Pixel;
.....
template <class T>
void Image2D<T>::Char2Pixel(Pixel * c, T *p, int dimx, int dimy){
int i,j,k=0;

for(i=0;i<dimy;i++)
for(j=0;j<dimx;j++,k++){
p[k] = (T) c[k];
}
}

I can compile the class successfully. Now, I'm trying to generate a
shared library, but during the linking process I get the following
errors for all the my functions.

.....
libexample.so: undefined reference to `Image2D<unsigned
char>::Char2Pixel(unsigned char*, unsigned char*, int, int)'
libexample.so: undefined reference to
`Image2D<short>::Char2Pixel(unsigned char*, short*, int, int)'
libexample.so: undefined reference to
`Image2D<float>::Char2Pixel(unsigned char*, float*, int, int)'
.....

Any ideas what I'm doing wrong with my templates?

Thanks!

Jul 4 '06 #1
2 1192
In article <11*********************@h44g2000cwa.googlegroups. com>,
ne*******@yahoo.com says...
Hello,
I have a class with a number of functions like this one.
[ template code elided ... ]
I can compile the class successfully. Now, I'm trying to generate a
shared library, but during the linking process I get the following
errors for all the my functions.
Most compilers require that the source code to a template is visible
anywhere that template is used. A few support support export, so you
can put a template into a separate object file. I doubt any supports
putting one into a shared library though.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 4 '06 #2
neojohn75 wrote:
I have a class with a number of functions like this one.

typedef unsigned char Pixel;
....
template <class T>
void Image2D<T>::Char2Pixel(Pixel * c, T *p, int dimx, int dimy){
int i,j,k=0;

for(i=0;i<dimy;i++)
for(j=0;j<dimx;j++,k++){
p[k] = (T) c[k];
}
}

I can compile the class successfully. Now, I'm trying to generate a
shared library, but during the linking process I get the following
errors for all the my functions.

....
libexample.so: undefined reference to `Image2D<unsigned
char>::Char2Pixel(unsigned char*, unsigned char*, int, int)'
libexample.so: undefined reference to
`Image2D<short>::Char2Pixel(unsigned char*, short*, int, int)'
libexample.so: undefined reference to
`Image2D<float>::Char2Pixel(unsigned char*, float*, int, int)'
....

Any ideas what I'm doing wrong with my templates?
It's in the FAQ:

http://www.parashift.com/c++-faq-lit...html#faq-35.13

Best regards,

Tom

Jul 4 '06 #3

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

Similar topics

3
by: Chris Stiles | last post by:
Hi -- Does anyone have any recommendations for simple web templating systems for python that also allow execution of python code within the the templates themselves ? So far I'm using...
6
by: chris | last post by:
Hi, After going back through the XSL tutorials and the help here I have largely solved the problem of merging two XHTML files, but one small detail remains... The parser outputs <html...
9
by: Mike King | last post by:
What is the XPath expression that selects the value attribute in the following xml? <?xml version="1.0"?> <root xmlns="http://a/" xmlns:a="http://a/"> <child a:value="1"/> </root>
1
by: Scott | last post by:
The following is the XML I have to work with. Below is the question <Table0> <CaseID>102114</CaseID> <CaseNumber>1</CaseNumber> <DateOpened>2005-06-14T07:26:00.0000000-05:00</DateOpened>...
4
by: ³\¥\»\ | last post by:
I have reviewed all famous and mature CMS but there are ALL too complicated, too fancy and the result is that you can not totally control what you want in your website. I hope there is a CMS with:...
5
by: Support | last post by:
Hello: I have the following code that currently needs to go in every page. QUESTION 1) Can Page_Preinit go somewhere else more global like Global.asax so that I dont have to copy this code in...
75
by: Steven T. Hatton | last post by:
No, this is not a troll, and I am not promoting Java, C-flat, D, APL, Bash, Mathematica, SML, or LISP. A college teacher recently posted to this newsgroup regarding her observation that there has...
17
by: JohnQ | last post by:
Is that I can approximate using my ideal of a language in it. On the flip side, what I dislike most about it is all the flak/protecting-the-golden-calf one gets when using it that way. I think a...
3
by: stdlib99 | last post by:
Hi, I have a simple question regarding templates and meta programming. I am going to try and work my way through the C++ Template Metaprogramming, a book by David Abrahams and Aleksey...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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.