Page 2 of 2
Posted: Thu May 03, 2007 11:25 pm
by Candy
pcmattman wrote:Actually there's another reason why that loader has to go first - it holds the multiboot header...
I guess you can tell it to put the multiboot header in its own section and then place it. I'm not sure you can tell it not to throw it away though, but then again you'll probably use it from your code so it won't remove it anyway.
Re: Linking fails with templates?
Posted: Thu May 03, 2007 11:44 pm
by B.E
pcmattman wrote:Any ideas?
I need to see the whole header file. What the errors till me is that it can't find the correct implementation. Just remember the template can never be compiled. only the resulting code from the template can be compiled (i.e each time a template is used with different args, a copy of that code is compiled with them arguments and added to the final executable. by arguments I mean the stuff between the < and >).
Posted: Fri May 04, 2007 12:40 am
by pcmattman
Here you go:
Code: Select all
#include <console.h>
template< class T >
class Accumulator
{
public:
Accumulator() { };
~Accumulator() { };
T Value();
T operator = ( T val );
private:
T m_val;
};
template< class T > T Accumulator<T>::Value()
{
return(m_val);
}
template< class T > T Accumulator<T>::operator = ( T val )
{
return( m_val = val );
}
Note that when I told G++ to link as well as compile (ie. not doing the link myself) there were no errors. The only problem was it complained about the loader object format (assembled via NASM). And there is no way I'm converting it to GAS syntax.
Edit: OK, here's what happens with the following command line:
Code: Select all
gpp -I "include" -masm=intel loader.obj *.cc */*.cc -nostdlib -fno-builtin -fno-rtti -fno-exceptions -Wl,-T linker.ld
Outputs:
Code: Select all
Warning: input file is not COFF or stubbed COFF
loader.obj is an ELF object file assembled with NASM. Any ideas?
Edit 2: Wait. The error comes from 'stubify.exe' - converting the final image to an exe??? I'm playing around with the command line. Once I've got it working, I'm making a makefile so I don't keep getting complaints about command line length...
Edit 3: Nope, still the same problems... I just can't get templates to work!
Code: Select all
c:/djgpp/bin/ld.exe: c:/djgpp/tmp/ccnnBa6D.o: Unrecognized storage class 127 for /4 symbol `Accumula
tor<int>::Accumulator()'
c:/djgpp/bin/ld.exe: c:/djgpp/tmp/ccnnBa6D.o: Unrecognized storage class 127 for /44 symbol `Accumul
ator<int>::test()'
c:/djgpp/bin/ld.exe: c:/djgpp/tmp/ccnnBa6D.o: Unrecognized storage class 127 for /87 symbol `Accumul
ator<int>::operator=(int)'
c:/djgpp/bin/ld.exe: c:/djgpp/tmp/ccnnBa6D.o: Unrecognized storage class 127 for /127 symbol `Accumu
lator<int>::Value()'
Posted: Fri May 04, 2007 5:13 am
by os64dev
And there is no way I'm converting it to GAS syntax
You might reconsider this because the problems now seem very familiar and i fixed it by converting the bootloader to GAS and because of the integration with the C++ part it works perfectly. My bootsector does not contain any data, only code, to load the stage1 loader. .. but that is not what you want to hear.
You can either use a cross-compiler and also build your C++ code as ELF or you have to convert the loader.obj to COFF format. I guess you can use objcopy for that.
Or you could build you loader.obj with 'nasm -f coff' to compile it in coff format.
Posted: Fri May 04, 2007 4:33 pm
by pcmattman
OK. The main reason why I don't want to convert is because there's a lot of code that would then need to be rewritten.
Posted: Fri May 04, 2007 9:55 pm
by B.E
I have no idea, but have you rebuilt the source from scratch lately. Some times a linker erroris can be solved simply by rebuilding the whole thing from scratch.
Posted: Fri May 04, 2007 9:57 pm
by pcmattman
Yes, multiple times
And I've rewritten the loader in GAS (GAS is actually really nice to read).
Posted: Mon May 28, 2007 3:55 pm
by pcmattman
OK, I must know nothing about templates... Visual C++ throws this error on some template code I wrote:
Code: Select all
main.obj : error LNK2001: unresolved external symbol "public: int __thiscall CLinkedList<int>::test(int)" (?test@?$CLinkedList@H@@QAEHH@Z)
This is insanity! Can someone please save me and tell me how to do the templates properly?
Edit: OK, almost there! New problem:
Code: Select all
c:/djgpp/bin/ld-elf.exe: C:\OSDev\MattiseOS\CPP_Kernel\kernel.o: Unrecognized storage class 127 for
/4 symbol `__ZN4TestIiE2hiEi'
From the following:
Code: Select all
template< typename _T >
class Test
{
public:
void hi( _T );
};
template< typename _T > void Test<_T>::hi( _T t )
{
kprintf( "hi!" );
}
Any ideas?
Edit 2: Actually, it's not a new problem... This is somewhat frustrating.
Posted: Sat Jun 02, 2007 7:46 pm
by pcmattman
I'm rebuilding my cross-compiler. I'm so sick of this.
Posted: Sat Jun 02, 2007 10:39 pm
by pcmattman
Ha! Beat that, GCC! I win!
Guess what? I compiled in my newly-built (rebuilt) cross-compiler, and BAM!!! Templates work!
I'm a very happy person!