Page 1 of 2
linking question
Posted: Thu Aug 09, 2007 3:46 pm
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
Posted: Thu Aug 09, 2007 3:53 pm
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.
Posted: Thu Aug 09, 2007 3:58 pm
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
Posted: Thu Aug 09, 2007 4:10 pm
by Alboin
Try removing the _ from main in kernel.c.
Posted: Thu Aug 09, 2007 4:14 pm
by Meshounah
it didn't work still same thing
Posted: Fri Aug 10, 2007 2:16 am
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
Posted: Fri Aug 10, 2007 11:23 am
by Meshounah
yes it does not work i still get the same error
Posted: Tue Aug 14, 2007 9:52 am
by Meshounah
i tried everything i can think of still same thing
Posted: Tue Aug 14, 2007 10:12 am
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
Posted: Tue Aug 14, 2007 2:25 pm
by Meshounah
Shot at 2007-08-14
Posted: Tue Aug 14, 2007 2:28 pm
by Meshounah
or could you post a barebone c kernel?
Posted: Tue Aug 14, 2007 2:55 pm
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.
Posted: Tue Aug 14, 2007 2:59 pm
by Meshounah
ok i started with a new barebone kernel and i went nowhere before i had a problem
start.o file not recognized: file format not recognized
Posted: Tue Aug 14, 2007 3:01 pm
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
Posted: Tue Aug 14, 2007 3:04 pm
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.