ld: unknown option: -T

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.
Post Reply
abcdwill
Posts: 8
Joined: Thu Mar 05, 2009 5:37 pm

ld: unknown option: -T

Post by abcdwill »

Hello,

I am interested in creating my own operating systems to learn more about their inner workings and push myself to improve my programming skills, however the limited ld tool that came with my Mac is holding me back. The tutorial I am using instructs me to use the -T option for gnu linker scripts, however I get the error:

Code: Select all

ld: unknown option: -T
The page of the tutorial I am following is: http://osdever.net/bkerndev/Docs/basickernel.htm (at the bottom)
The error occurs in the following area of my script:

Code: Select all

echo Finished compiling! Now linking...
echo

#
# Error occurs on the line below due to the absence of the
# -T option in the ld binary included on my Mac
# which has OS X 10.5 Leopard installed, if you're
# wandering
#
ld -T link.ld -o ${bldd}/kernel.bin start.o

if [ $? -gt 0 ]; then echo "LD failed."; read -p "Press any key to exit..."; exit 1; fi
echo Finished linking!
echo creating Kernel Image...
touch $kimg
I have searched the internet and many forums yet have not found a solution. I am aware that ld is a part of binutils, a gnu package. I attempted to install binutils, however ld was not included in the output directory. If I am forced to, then I can use my linux virtual machine, however it is very difficult to transfer files between Mac OS X and Ubuntu, so I'd prefer to be able to develop natively on my Mac.

If anyone can help me with a workaround or a port of ld which includes the -T option, I'd very much appreciate it.

Thank you in advance for any replies :D
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:

Re: ld: unknown option: -T

Post by Combuster »

GCC Cross-Compiler <- for all your toolchain related problems (and yes that has been asked a dozen times before)
"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 ]
abcdwill
Posts: 8
Joined: Thu Mar 05, 2009 5:37 pm

Re: ld: unknown option: -T

Post by abcdwill »

Combuster wrote:GCC Cross-Compiler <- for all your toolchain related problems (and yes that has been asked a dozen times before)
Thanks, but unfortunately, this has not worked. I have compiled binutils countless times on my mac, which does not compile ld, and on ubuntu for my mac, which yet again does not include ld (i386-apple-darwin9.6.0 and i686-apple-darwin9.6.0)

If anyone has instructions on how to compile the gnu linker (ld) for mac os x leopard (intel core duo), or has a precompiled version, then please respond. I have found other topics like this, yet they do not have any working solutions. Macports and other ports do not have ld, and binutils does not install it. I had come across GCC Cross-Compiler before, yet not understood how it could have helped me.

BTW, I have searched this forum yet all mention about downloading the latest gcc and binutls, and then to compile, using cross-compiler. I have followed the tutorial and can obtain an ld executable for linux, however no luck in compiling one for my Mac. Please could someone either send me a dmg or other archive/image (e.g.: rar, tar.gz, zip, etc...) of a full binutils suite for mac os x, including ld, or else provide instructions that definitely work, as no instructions I have tried have resulted in a compiled ld executable for Mac OS X Leopard Intel Core Duo (iMac). All help appreciated.
abcdwill
Posts: 8
Joined: Thu Mar 05, 2009 5:37 pm

Re: ld: unknown option: -T

Post by abcdwill »

berkus wrote:Looks like quite a good task to weed out people who cannot solve basic problems, ain't it?

Check configure output, it might tell you WHY binutils decides not to build ld. Run make in ld directory alone and note any errors. Check make install target to see it actually includes ld. Check built output directory for ld binary and copy it manually if needed.
Thanks, sorry if I seem a bit slow, I don't use ./configure scripts a lot, however most times they just work :D .

OK, I checked the log and found it said ld was precompiled, however I could not find anything online about that, so I entered the ld directory and tried to cross-compile to my mac and it said that the i386 / i686-apple-darwin9.6.0 target is unsupported. However I'm confused as other topics claim it's possible, so I used 'grep mac' on the file configure.tgt in the ld directory and found 'mach', which I had noticed in previous internet searched regarding my problem, so I am now compiling for mach. I'm not sure if this will work, though, so could someone give me the target architecture I should use to compile ld for mac os x intel core duo, as apparently it is possible to compile ld from binutils for macs, yet I can not seem to find the architecture.

Thanks for any responses, in the meantime I'll reply when I have finished compiling for mach and tested it on my mac.
abcdwill
Posts: 8
Joined: Thu Mar 05, 2009 5:37 pm

Re: ld: unknown option: -T

Post by abcdwill »

berkus wrote:GCC Cross-Compiler wiki link given above states the following:

Code: Select all

export TARGET=i586-elf
The OS Specific Toolchain mentions a few files you might want to look into to figure what exactly you should specify for TARGET.
Thank you very much =D> , I'm now sending the compiled files to my mac for testing. Sorry about the easy questions, I am quite new to these processes and so was unaware of the easily obtainable information

EDIT: Unfortuanetly, this binary (i586-elf) does not work on my mac :(

Code: Select all

-bash: ./ld: cannot execute binary file
I will try, though, to compile it again for my mac target architecture by adding an architecture using your link
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: ld: unknown option: -T

Post by xenos »

So, you're compiling a Canadian Cross... Maybe you should have a look at the wiki for some information on how to set --build, --host and --target for Canadian Cross compilers.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
abcdwill
Posts: 8
Joined: Thu Mar 05, 2009 5:37 pm

Re: ld: unknown option: -T

Post by abcdwill »

XenOS wrote:So, you're compiling a Canadian Cross... Maybe you should have a look at the wiki for some information on how to set --build, --host and --target for Canadian Cross compilers.
To be honest, I don't see the point of me needing to do cross compilation as it seems easier and faster to just do it natively on my mac. The problem is that ld in binutils does not, apparently, have mac support. I tried adding my architecture to ld/configure.tgt, however when I run

Code: Select all

CC=gcc ./configure --prefix=$PREFIX --disable-nlm && make all && make install
it says:

Code: Select all

checking where to find the target ld... host tool
I know that mac includes a version of ld, however it does not include the feature I desperately need (the -T option), and binutils doesn't want to compile ld.

I checked the configure.tgt for the rest of the packages and they compile most architectures using vanilla, so I added that line to configure.tgt for ld. Firstly, can someone confirm if this is correct, and secondly, can someone help me force the binutils source into compiling ld for me. Of course, if someone has a mac and wants to help save me and all the posters on this topic a lot of time, maybe someone could kindly give me a precompiled version of ld for the intel core due iMac running Mac OS X leopard, otherwise, just help in compiling ld.

BTW, just to recap, a restricted version of ld is installed on my machine, so I have downloaded the gnu binutils source code, added my architecture to ld's configure.tgt file, and when I run ./configure it says it will not compile because it has already been found on the host machine. Thanks again for all help!

PS. An architecture which runs perfectly after compilation is:

Code: Select all

i386-apple-darwin9.6.0
quok
Member
Member
Posts: 490
Joined: Wed Oct 18, 2006 10:43 pm
Location: Kansas City, KS, USA

Re: ld: unknown option: -T

Post by quok »

Wow, another post about OS Deving on OS X. I don't know why so many people have had problems with this. I dev almost exclusively on OS X these days.

The GCC and binutils packages that are available from the XCode DVD and apple's website only create Mach-O executables, as that is the format that is used on OS X. Mach-O doesn't use 'ld', it uses dylib, which isn't included in binutils and is a separate project.

The i386-elf-gcc and i386-elf-binutils packages that are available in macports now are broken, and have been for some time. But if you search the macports bug reports, you'll find the fixes.

Other than that, just follow the GCC_Cross-Compiler tutorial. I'll guarantee it works if you use GCC 4.2.4 and Binutils 2.18, as that's exactly what I run.

I think it's time for a "OSDev on OS X FAQ."

EDIT: On the GCC_Cross-Compiler tutorial, just do "Step 1 - Bootstrap" and forget about everything else on that page. You won't need a C library, a full cross compiler, or a native compiler anytime soon at all. A naked compiler like that will help you avoid a LOT of other beginner mistakes as well, like attempting to link against your host libs.

EDIT 2: I guess this weekend I'll make sure various other GCC and Binutils combinations work as well, and maybe even build DMGs of them like I said I would in the past, heh!
Last edited by quok on Fri Mar 06, 2009 5:23 pm, edited 2 times in total.
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:

Re: ld: unknown option: -T

Post by Combuster »

Good to know that the crosscompiler tutorial isn't broken for mac hosts. I'll be adding that to the article.
Edit: FAQ entry added
"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 ]
abcdwill
Posts: 8
Joined: Thu Mar 05, 2009 5:37 pm

Re: ld: unknown option: -T

Post by abcdwill »

Thank you very much to all those who helped me, especially quok for clarifying how to do it :D
I now have a working copy of ld and my first os (even though it just freezes the computer in an endless loop :P ) Sorry if this post was unnecessary, and thanks Combuster for the FAQ, I'm sure it'll help many get started!

Thanks again
Post Reply