Making library modules (libc etc)

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.
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Making library modules (libc etc)

Post by t0xic »

How can I modulize (is this a word?) my kernel? I have reached about 10-12 different C files and apparently "ld" can't link that many. I am compiling under windows xp.

This is my compile line:

Code: Select all

tools\ld -T link.ld -Map os.txt -o kernel.bin loader.o main.o inc.o x86.o video.o string.o malloc.o kb.o core.o floppy.o stdio.o 
Thanks,

--t0xic
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

1: Don't use djgpp :wink:
2: link in steps
ld -i -o intermediate1.o file1.o file2.o file3.o
ld -i -o intermediate2.o file4.o file5.o file6.o
ld -i -o intermediate3.o file7.o file8.o file9.o
ld ..... intermediate1.o intermediate2.o intermediate3.o
IIRC, that is
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Post by t0xic »

For some reason when I use "ld -i" with a.out asm files, it won't work :(
Anyone else have an idea?
Thanks for your help,

--t0xic
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post by jnc100 »

ar rcs -o intermediate1.o file1.o file2.o file3.o
ar rcs -o intermediate2.o file4.o file5.o file6.o
ar rcs -o intermediate3.o file7.o file8.o file9.o
ld ..... intermediate1.o intermediate2.o intermediate3.o

Again, if I remember correctly...

Regards,
John.
User avatar
astrocrep
Member
Member
Posts: 127
Joined: Sat Apr 21, 2007 7:21 pm

Post by astrocrep »

Your exceeding the command line length in dos...

-Rich
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

I have reached about 10-12 different C files and apparently "ld" can't link that many
Your exceeding the command line length in dos...
And that is why makefile are a lot better. Try learning those. Do you use cygwin under windows?
Author of COBOS
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Either use a makefile as suggested, or have all your binaries in a single directory and link with the *.o wildcard.

Adam
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

AJ wrote:Either use a makefile as suggested, or have all your binaries in a single directory and link with the *.o wildcard.
Hmmm... I've never used anything as crippled as DJGPP, but does any of this really solve the problem?

make does use the system's command shell for executing commands. Does the make in the DJGPP package really get around the limitations of cmd.exe?

And the wildcard gets expanded before being passed to the command interpreter, so again I'd guess this doesn't help.

Bottom line, use real tools (Cygwin). ;)
Every good solution is obvious once you've found it.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

I use djgpp and make works fine with much longer command lines than you can get away with in batch files run in cmd.

I still haven't managed to get a cygwin cross compiler working properly. I know, I know - it must be me because the exact instructions on the wiki work for everyone else...

So far, however, no problems with djgpp so the incentive to use Cygwin just isn't there.

Adam
User avatar
AndrewAPrice
Member
Member
Posts: 2309
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Making library modules (libc etc)

Post by AndrewAPrice »

t0xic wrote:How can I modulize (is this a word?) my kernel? I have reached about 10-12 different C files and apparently "ld" can't link that many. I am compiling under windows xp.

This is my compile line:

Code: Select all

tools\ld -T link.ld -Map os.txt -o kernel.bin loader.o main.o inc.o x86.o video.o string.o malloc.o kb.o core.o floppy.o stdio.o 
Thanks,

--t0xic
try this:

Code: Select all

ren loader.o loader.ao
tools\ld -T link.ld -Map os.txt -o kernel.bin loader.ao *.o
That will rename loader.o to loader.ao so that is it attached to the beginning of the file.
My OS is Perception.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Making library modules (libc etc)

Post by AJ »

MessiahAndrw wrote:That will rename loader.o to loader.ao so that is it attached to the beginning of the file.
Of course, if you are using a format with relocation and entry point information, that's not needed. If you are using flat binary, it is.
Last edited by AJ on Thu May 24, 2007 2:34 pm, edited 1 time in total.
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Post by t0xic »

Thanks for your help everyone.

The wildcard trick does work, and I have been trying to shy away from djgpp as much as possible. I haven't figured out how to use cygwin from batch files (make is too complex for me lol)
Could anyone show me an example of a cygwin batch or make file?

Thanks again,
--t0xic
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

jnc100 wrote:ar rcs -o intermediate1.o file1.o file2.o file3.o
ar rcs -o intermediate2.o file4.o file5.o file6.o
ar rcs -o intermediate3.o file7.o file8.o file9.o
ld ..... intermediate1.o intermediate2.o intermediate3.o

Again, if I remember correctly...

Regards,
John.
That's grueling with respect to the output files. Archive files (which AR produces) have the default extension .a, not .o. Objdump will have a fit.

For a scalable approach, I would incrementally archive in each new file after compiling it

Code: Select all

gcc -c -o file1.o file1.c
ar rcs -o intermediate.a file1.o
gcc -c -o file2.o file2.c
ar rcs -o intermediate.a file2.o
...
gcc -c -o fileX.o fileX.c
ar rcs -o intermediate.a fileX.o
ld ..... -o output intermediate.a
On the other hand, replace your tools by things that aren't limited to humanly reachable limits. I can't configure bochs (./configure, not bochsrc) in Windows because I tend to use too many options.
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post by Alboin »

Not to be off topic, but I wonder what someone's expression will be in 20 years, looking back on a topic like this:
"I can't compile...because of command line...limits?"

...<long pause>...

Oh my giddy Aunt!

...<long pause; sheds a little tear.>...

Well, it's a good thing I don't use this 'Windows' thing they keep referring to.

<Closes Firefox and goes back to working on his Linux PC.>
Seriously, though. Isn't it a little ridiculous that their prompt has length limits?
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Compling many files multiple directorys; pattern matching

Post by Kevin McGuire »

How can I modulize (is this a word?) my kernel? I have reached about 10-12 different C files and apparently "ld" can't link that many. I am compiling under windows xp.
You might try breaking certain parts into multiple directories:

<inside \project\src\mm\>
gcc -c *.c
cp *.o \project\obj\
<inside \project\src\kernel\>
gcc -c *.c
cp *.o \project\obj\
<inside \project\src\vfs\>
...
..
<inside \project\drivers\...>
...
<final link inside \project\obj>
gcc *.o -o kernel
Last edited by Kevin McGuire on Sat May 26, 2007 5:20 pm, edited 1 time in total.
Post Reply