Mail Archives: djgpp/1995/07/13/10:08:14
Hi,
I was facing some problems with template instantiation under g++ 2.6.3
and thought some one more experienced with the compiler could provide me a so-
lution or workarround... Here comes a little programm that generates the pro-
blem:
----------------------------------------8<----------------------------- v1.h -
// test header //
void foobar();
template<class T>
class bar {
T *p;
int k;
bar();
~bar();
void kiki(T a);
friend bar2;
};
template<class T>
bar<T>::bar()
{
printf("constructor");
}
template<class T>
bar<T>::~bar()
{
printf("constructor");
}
template<class T>
void bar<T>::kiki(T a)
{
printf("function");
}
class bar2 {
bar<int> kuku;
int b;
};
----------------------------------------8<---------------------------- v1.cc -
// test code //
#include <stdio.h>
#include "v1.h"
void foobar()
{
int a,b;
b = 3;
printf("kokokokokoko\n");
a = b + 2;
printf("%d",a);
}
i compile with
gcc -S -c -m486 -O3 t.cc
and get the following output:
.file "v1.cc"
gcc2_compiled.:
___gnu_compiled_cplusplus:
.text
LC0:
.ascii "kokokokokoko\12\0"
LC1:
.ascii "%d\0"
.align 4
.globl _foobar__Fv
_foobar__Fv:
pushl %ebp
movl %esp,%ebp
pushl $LC0
call _printf
pushl $5
pushl $LC1
call _printf
movl %ebp,%esp
popl %ebp
ret
LC2:
.ascii "constructor\0"
.align 4
.globl ___t3bar1Zi
___t3bar1Zi:
pushl %ebp
movl %esp,%ebp
pushl %ebx
movl 8(%ebp),%ebx
pushl $LC2
call _printf
movl %ebx,%eax
movl -4(%ebp),%ebx
movl %ebp,%esp
popl %ebp
ret
.align 4
.globl __$_t3bar1Zi
__$_t3bar1Zi:
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %ebx
movl 8(%ebp),%esi
movl 12(%ebp),%ebx
pushl $LC2
call _printf
addl $4,%esp
testb $1,%bl
je L33
pushl %esi
call ___builtin_delete
L33:
leal -8(%ebp),%esp
popl %ebx
popl %esi
movl %ebp,%esp
popl %ebp
ret
LC3:
.ascii "function\0"
.align 4
.globl _kiki__t3bar1Zii
_kiki__t3bar1Zii:
pushl %ebp
movl %esp,%ebp
pushl $LC3
call _printf
movl %ebp,%esp
popl %ebp
ret
as u see the code for the constructor/destructor and the test function
of bar is generated even though it is NOT used... I have many .cc files which
i want to compile to a library (.a file)... But they all include a header file
with class definitions and the public ctors/dtors and public functions are ge-
nerated to all of them so i get multiple definition errors when i link my lib-
rary to a programm. Is there any solution to this problem. Btw the other compi-
ler i use (Watcom) doesnt generate multiple definition errors so i guess i am
not doing something wrong... any help appreciated...
tmL-
- Raw text -