Page 1 of 1
Linking
Posted: Mon Mar 19, 2007 10:58 am
by salil_bhagurkar
I have a problem with ld (or may be gcc) . I have about 30 files in my kernel. I compile all, then link groups into object files using the '--relocatable' switch of ld. Then at the end i link all the object files of the groups.
e.g.:
ld -T (linkscript) -o image res1.o res2.o
ld --relocatable -o res1.o fdc.o hd.o
ld --relocatable -o res2.o lpt.o ser.o
While linking the whole kernel at the end i get an error from ld that it found multiple definitions of symbol "__environ" which i never declared in any of my files.
It is found in one or two of my source files which are not different than others in any way that could cause such a problem
--So what is the cause of this "__environ"?
Posted: Mon Mar 19, 2007 11:36 am
by Solar
__environ usually points to the string field holding the environment variables... dragged in some unwanted dependencies, perhaps?
Posted: Mon Mar 19, 2007 11:47 am
by salil_bhagurkar
I am unaware of that term 'dependencies'. Do you mean i included some unwanted headers or declared protorypes of functions that do not exist?
Posted: Mon Mar 19, 2007 12:15 pm
by Brynet-Inc
salil_bhagurkar wrote:I am unaware of that term 'dependencies'. Do you mean i included some unwanted headers or declared protorypes of functions that do not exist?
Possibly linking with a library from your development system? could be possibly including a system header.. (Why?.)..
I can't be sure..
Posted: Mon Mar 19, 2007 12:50 pm
by salil_bhagurkar
I am surely not linking with any system library or including a system header. I thought giving a switch '-ffreestanding' would help (i referred gcc man) but even that made no difference...
Posted: Mon Mar 19, 2007 1:09 pm
by Brynet-Inc
salil_bhagurkar wrote:I am surely not linking with any system library or including a system header. I thought giving a switch '-ffreestanding' would help (i referred gcc man) but even that made no difference...
What are the commands do you use to build your kernel?
Posted: Mon Mar 19, 2007 1:15 pm
by salil_bhagurkar
All C compilations done with -c
and ld uses -T link.ld -o
Posted: Mon Mar 19, 2007 1:49 pm
by Brynet-Inc
Is your kernel Open Source? maybe someone else can track it down for you.. if not.. manually going through your source with the grep command would be recommended..
Posted: Mon Mar 19, 2007 3:05 pm
by pcmattman
salil_bhagurkar wrote:All C compilations done with -c
and ld uses -T link.ld -o
Try BareBones in the Wiki for your GCC and LD command lines... I think you'll find that there's more to them then just -c...
Posted: Mon Mar 19, 2007 3:19 pm
by Combuster
A
GCC Cross-Compiler is recommended practice. If your kernel wont link properly, then the barebones might suffer the same problem...
Posted: Mon Mar 19, 2007 3:35 pm
by Mikae
I thought giving a switch '-ffreestanding' would help (i referred gcc man) but even that made no difference...
Try also '-nostdlib' option. May be, it will help.