Page 1 of 1

LD help.. :-S

Posted: Fri Oct 31, 2008 2:44 pm
by cometkeeper
Well, sorry because this is a very stupid question... a believe... but I can't figure the problem...

Many months ago I created a little kernel in cpp and gcc/ld worked right.

Now, I complie the same files and it doesn't work.

I use a kernel32asm:

Code: Select all

        bits 32

        extern _start

AsmKernel:
        jmp _start
        jmp $
the _start is defined in the cpp:

kernel32.cpp

Code: Select all

extern "C" void start();

extern void start()
{
        while(1)
        {}
}
The commands are:

Code: Select all

nasm -f aout kernel32asm.asm -o kernel32asm.o
gcc -c kernel32.cpp -o kernel32.o -fno-rtti -fno-exceptions -I include
ld -Ttext=0x20000 -o kernel32.tmp kernel32asm.o kernel32.o -e 0x0
objcopy -R .note -R .comment -S -O binary kernel32.tmp kernel32.bin
The ld error si:
kernel32.o(.text+0x0):kernel32.cpp: multiple definition of `start'
kernel32asm.o(.text+0x0):kernel32.cpp: first defined here

The same problem comes up if I use some include file, for example for functions like "setcursorpos" etc... All functions come out the error: "multiple defition"....

The only thing I changed is nasm. I use the same gcc (3.1) and now the nasm 2.05. Unfortunately I haven't the old nasm, but maybe this is not the problem...

Can anyone help me?

Thank you very much....
CometKeeper

Re: LD help.. :-S

Posted: Fri Oct 31, 2008 5:35 pm
by Virtlink
cometkeeper wrote: kernel32.cpp

Code: Select all

extern "C" void start();

extern void start()
{
        while(1)
        {}
}
Why do you have your start function definition declared as 'extern'? Seems to me that it's what could cause your problem.

- Virtlink

Re: LD help.. :-S

Posted: Fri Oct 31, 2008 6:12 pm
by Troy Martin
IIRC extern declares it for use in other linked files. Or something like that.

*bets Brendan will come in any minute now*

Re: LD help.. :-S

Posted: Fri Oct 31, 2008 9:07 pm
by pcmattman
The extern should NOT be there. The extern keyword creates a weak reference to a symbol that allows the code to compile. Later on this reference is filled by the linker when the specified symbol is found.

Keep the extern "C", because that tells the C++ compiler not to mangle the name (among other things) but remove the extern from the start() declaration and it should work.

Re: LD help.. :-S

Posted: Fri Oct 31, 2008 9:29 pm
by Love4Boobies
Damn, everyone got here before me :lol:
except for Brendan :P

Re: LD help.. :-S

Posted: Sat Nov 01, 2008 12:41 am
by cometkeeper
Thank you...

Well... How can I explain that... because I can't believe it myself :D

Ok, let's start saying that I think I solved the problem.

See the ld error:
kernel32.o(.text+0x0):kernel32.cpp: multiple definition of `start'
kernel32asm.o(.text+0x0):kernel32.cpp: first defined here
Why .cpp is here?

I tried with ubuntu and all went right!

See also this: when I get in command-mode I can see this:
C:\OS_DEV_2007\

After starting a simply "gcc -v" I get
C:\OS_DEV~1\

Well, if I rename kernel32asm.o in ka.o, all work right.
If input-file's names are longer than 8+3 chars ld goes out of mind :D

Can anyone explain this to me? Months ago (other windows installation) this didn't happen... :-s

Thanks...