linkage -O3 templates

A

Alexander Stippler

Hi,

I've got some linking trouble. I've got a project with many template
classes. Everything works fine as long as I do not use -O3 for optimizing.
If I use it, I get some linker error about undefined references. All
methods, the linker misses, are empty member functions of template classes.
So the compiler optimizes them away with -O3, but the linker still needs
them!?!. What can I do about it?

regards,
Alex
 
J

Jacques Labuschagne

Alexander said:
Hi,

I've got some linking trouble. I've got a project with many template
classes. Everything works fine as long as I do not use -O3 for optimizing.
If I use it, I get some linker error about undefined references. All
methods, the linker misses, are empty member functions of template
classes. So the compiler optimizes them away with -O3, but the linker
still needs them!?!. What can I do about it?

You say those functions are empty - so why do they exist? Apart from
trimming pointless code your other option seems to be to look at the GCC
man page and enable the individual optimisations that would be done by -O3
minus the one that removes empty functions.
 
A

Alexander Stippler

Jacques said:
You say those functions are empty - so why do they exist? Apart from
trimming pointless code your other option seems to be to look at the GCC
man page and enable the individual optimisations that would be done by -O3
minus the one that removes empty functions.

Sometimes one needs empty functions. Just think of constructors, which would
not exist otherwise (as soon as you have another constructor). And I'm not
looking for a workaround. I'm looking for a solution.

regards,
alex
 
C

Christoph Rabel

Alexander said:
Sometimes one needs empty functions. Just think of constructors, which would
not exist otherwise (as soon as you have another constructor). And I'm not
looking for a workaround. I'm looking for a solution.

It could be a bug in the optimizer, have you tried to compile it with a
different version of the compiler? (2.95, 3.0, 3.1, ...)

Hmm, you probably have to ask this on a gcc mailing list. Maybe they can
help you.

Christoph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,813
Members
47,357
Latest member
sitele8746

Latest Threads

Top