LD help.. :-S

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
cometkeeper
Posts: 5
Joined: Sun Nov 19, 2006 11:11 am
Location: Italy
Contact:

LD help.. :-S

Post 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
Virtlink
Member
Member
Posts: 34
Joined: Thu Jun 05, 2008 3:53 pm
Location: The Netherlands
Contact:

Re: LD help.. :-S

Post 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
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: LD help.. :-S

Post 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*
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: LD help.. :-S

Post 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.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: LD help.. :-S

Post by Love4Boobies »

Damn, everyone got here before me :lol:
except for Brendan :P
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
cometkeeper
Posts: 5
Joined: Sun Nov 19, 2006 11:11 am
Location: Italy
Contact:

Re: LD help.. :-S

Post 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...
CometKeeper... A Dream Guardian...
Post Reply