linking question

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.
Meshounah
Member
Member
Posts: 38
Joined: Sun Jun 24, 2007 6:48 pm

linking question

Post by Meshounah »

i'm currently keeping my source in ~/os and i have the following files loader.s, loader.o, kernel.c, kernel.o, and linker.LD but i don't really know how to actually link them together in cygwin. thank you
chik'n
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post by Alboin »

You have to use ld.

It should be something like:

Code: Select all

ld -Tlinker.LD loader.o kernel.o -o kernel.bin
However, forgive me if my syntax is a little off for some reason or another. ;)
C8H10N4O2 | #446691 | Trust the nodes.
Meshounah
Member
Member
Posts: 38
Joined: Sun Jun 24, 2007 6:48 pm

Post by Meshounah »

ok i did that but it doesnt work for me:

loader.o: in function 'loader' :
loader.s:<.text+0x14>: undefined reference to 'main'

and now i really don't know whats wrong :shock:
Attachments
kernel.zip
my source
(1.72 KiB) Downloaded 138 times
chik'n
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post by Alboin »

Try removing the _ from main in kernel.c.
C8H10N4O2 | #446691 | Trust the nodes.
Meshounah
Member
Member
Posts: 38
Joined: Sun Jun 24, 2007 6:48 pm

Post by Meshounah »

it didn't work still same thing
chik'n
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

An objdump of kernel.o shows that your .c function _main is being compiled as __main. Your asm loader is trying to reference _main. Are you sure that removing the leading underscore in the c file only does not work?

Cheers,
Adam
Meshounah
Member
Member
Posts: 38
Joined: Sun Jun 24, 2007 6:48 pm

Post by Meshounah »

yes it does not work i still get the same error
chik'n
Meshounah
Member
Member
Posts: 38
Joined: Sun Jun 24, 2007 6:48 pm

Post by Meshounah »

i tried everything i can think of still same thing :cry:
chik'n
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Do:

Code: Select all

nm main.o                #or whatever your object file is where 'main()' is defined.
nm start.o
And post the results.

JamesM
Meshounah
Member
Member
Posts: 38
Joined: Sun Jun 24, 2007 6:48 pm

Post by Meshounah »

Image
Shot at 2007-08-14
chik'n
Meshounah
Member
Member
Posts: 38
Joined: Sun Jun 24, 2007 6:48 pm

Post by Meshounah »

or could you post a barebone c kernel?
chik'n
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

Are you using a proper crosscompiler? You appear to call alloca() which you really shouldn't. Also, your compiler appears to prefix underscores which is just bad.

What this reads:

The first file defines _main and requires ___main and __alloca (both of which are nonsense, which is your compiler setup screwing up). The second file defines _loader and requires _main.

Your code is correct. Fix your compilers.
Meshounah
Member
Member
Posts: 38
Joined: Sun Jun 24, 2007 6:48 pm

Post by Meshounah »

ok i started with a new barebone kernel and i went nowhere before i had a problem :x

start.o file not recognized: file format not recognized
Attachments
os.zip
(1.66 KiB) Downloaded 116 times
chik'n
Meshounah
Member
Member
Posts: 38
Joined: Sun Jun 24, 2007 6:48 pm

Post by Meshounah »

Candy wrote:Are you using a proper crosscompiler? You appear to call alloca() which you really shouldn't. Also, your compiler appears to prefix underscores which is just bad.

What this reads:

The first file defines _main and requires ___main and __alloca (both of which are nonsense, which is your compiler setup screwing up). The second file defines _loader and requires _main.

Your code is correct. Fix your compilers.
how?

also i tried it under linux and cygwin still same thing
chik'n
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

http://www.osdev.org/wiki/GCC_Cross-Compiler of course.

Make a cross compiler and it will not pretend you're making a program for Windows.
Post Reply