Page 1 of 1

LD Linker - too manu arguments?

Posted: Mon Mar 16, 2009 2:00 pm
by mangaluve
Im using DJGPP/Nasm in Windows. To link my project, I use

Code: Select all

ld -T link.ld -o kernelcode.bin file1.o file2.o
and so on, where link.ld is

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
  .text 0x1000 :
  {
    *(.text)
  }
  .data :
  {
    *(.data)
  }
  .bss :
  {
    *(.bss)
  }
}
However, as I get more files, it seems like I cannot give more than 9 files as argument to ld. How can I solve this so I can link an arbitrary number of o-files?

Re: LD Linker - too manu arguments?

Posted: Mon Mar 16, 2009 2:07 pm
by Creature
You can try putting the object files you want to link inside the linker script instead of passing them to ld on the command line.

Add this below the SECTIONS for example:

Code: Select all

INPUT
(		
ObjFile1.o
ObjFile2.o
ObjFile3.o
ObjFile4.o
ObjFile5.o
/* ... */
)
I do it this way and have more than 9 object files and it works perfectly, let me know if this works.

Re: LD Linker - too manu arguments?

Posted: Mon Mar 16, 2009 5:24 pm
by Combuster
The real problem is DOS - it has a maximum command line size of about 255 characters, and therefore, so does DJGPP.

Re: LD Linker - too manu arguments?

Posted: Tue Mar 17, 2009 2:55 am
by AJ
Hi,

If you have that many source files, I would strongly suggest considering a make file. You'll be glad of it once your project expands more. See the Makefile tutorial on the wiki for more information.

As an alternative (that's not so flexible), you could always consider using file patterns for linking:

Code: Select all

ld -T link.ld -o kernelcode.bin *.o
If you are relying on a flat binary format, you may have to ensure that you link the file with your entry point first, so that the entry point is at the start of the file. For ELF, this won't matter because the file format itself defines an entry point.

Cheers,
Adam

Re: LD Linker - too manu arguments?

Posted: Tue Mar 17, 2009 3:25 am
by mangaluve
Thanks for the replies! I tried the last suggestion, linking *.o, and it works perfectly, although I think Im gonna look into make files!

Re: LD Linker - too manu arguments?

Posted: Tue Mar 17, 2009 3:45 am
by Solar
Unfortunately, all that 'make' does is passing the commands to the shell (i.e., the DOS box), so you'd be back to square one (unless I'm severely mistaken).

What you can do is using 'ar' to build a linker library, effectively collecting all the *.o files in one *.a file, one by one. (Don't know the exact command line options to do this, but it's possible.) The resulting *.a file can be passed to the linker as a single argument, and the linker will take from that linker library whatever *.o files it needs.

Re: LD Linker - too manu arguments?

Posted: Tue Mar 17, 2009 3:50 am
by AJ
Cygwin, anyone? :)

Re: LD Linker - too manu arguments?

Posted: Tue Mar 17, 2009 4:12 am
by Solar
*cough*

Second day of staying at home, caring for the wife (flu) and catering for the kids, and already my brain is guacamole mush. :-D

Yes, of course Cygwin is the way to go.

Re: LD Linker - too manu arguments?

Posted: Tue Mar 17, 2009 4:25 am
by AJ
Solar wrote:Second day of staying at home, caring for the wife (flu) and catering for the kids, and already my brain is guacamole mush. :-D
You have my sympathy! I went through all that that last week with my wife and boy. Then, to add insult to injury, you catch the damn thing yourself :(

Re: LD Linker - too manu arguments?

Posted: Tue Mar 17, 2009 11:58 am
by salil_bhagurkar
Alternatively:

Code: Select all

ld -T link.ld -o kernelcode.bin @files.txt
and files.txt can contain "file1.o file2.o"