How to install gnu ld on mac os x 10.6? - macos

I'm having a lot of trouble compiling the otherwise excellent Contiki OS on my macbook pro (with mac os x 10.6). Contiki actually uses a lot of GNU-specific features and options of GCC, AR, LD, and so on. So I installed those utilities via macports, but it looks like "port install binutils" does not install GNU ld, does it ?
So, the question is, how do I get GNU ld on my mac ? Is there a simple alternative to the hard-way (i.e. the wget, configure, make, make install way) ?

As far as I can tell, GNU binutils does not support the Mach-O format. None of the documentation mentions it, and some Googling turns up some recent messages indicating that it is not supported.
Now, you mention the Contiki OS, which looks to me like an embedded operating system. Are you needing to compile to a native executable, or are you trying to cross-compile for some other environment? MacPorts does include several ports of binutils for cross compilation.

$ port info binutils
(…) Tools are prefixed with g to avoid conflicts with original tools. (…)

Related

How to link homebrew gcc-4.x to gcc?

In OS X, how can I link gcc-4.8 from homebrew to gcc? I already tried to link gcc-4.8 to /usr/local/bin/gcc but this does not work. I really need this because I have shared makefiles in a course at the university.
There are at least a couple of options.
I have my GCC 4.8.2 installed under /usr/gcc/v4.8.2 and I ensure that /usr/gcc/v4.8.2/bin is on my PATH ahead of /usr/bin. That way, the undecorated name gcc means GCC 4.8.2. (This is on Mac OS X 10.9.1 Mavericks, just for the record.)
Specify CC=/usr/gcc/v4.8.2/bin/gcc on command lines, etc. Painful, so I don't regard it as a real option.
Make /usr/bin/gcc point to /usr/gcc/v4.8.2/bin/gcc instead of being an executable that runs clang.
I distrust modifying /usr/bin or /bin (or /sbin or /usr/sbin). I seldom use the system-provided Perl, for example, but always use my own build, using the same general technique.

Using gcc instead of clang in ghci or ghc

On Mac OSX 10.9, the default c compiler bundled with Xcode is clang. I installed gcc-4.9 with homebrew. Now I have two different gccs, one is clang, the other is gcc. The default is clang.
I want to use gcc when compiling Haskell files with ghc, and I want also gcc when I launch ghci. How to do this change?
Reproducing my directions I've been sharing with haskellers for the past few months via https://gist.github.com/cartazio/7131371
Type ghc --print-libdir
The output will be a path like /Library/Frameworks/GHC.framework/Versions/7.6.3-x86_64/usr/lib/ghc-7.6.3
Go to that directory and edit the settings file.
There'll be a line indicating the path to the C compiler. It'll probably say /bin/gcc
Change that line to /usr/local/bin/gcc-4.8 (or whichever gcc version you brew installed, such as /usr/local/bin/gcc-4.2)

Obtaining GCC for OSX with Developer Tools installed

I want to start working with C++0x. I see that GCC 4.7 has a fair amount of functionality available. I already have XCode 3.2 installed in /Developer
I downloaded: http://fileboar.com/gcc/snapshots/LATEST-4.7/gcc-4.7-20110528.tar.bz2
Can I somehow compile this in /opt/gcc-4.7? How do I then work with my path so I can compile with GCC 4.7 from the command-line but have OSX use the version it needs?
OSX does not need gcc to run - the Developer tools are optional. So you only need to choose between gcc's when you compile. In Xcode you chose explicitly the gcc andin Makefiles you can set $(CC) or similar to the full path.
Alternatively rename the gcc-4.7 gcc to gcc-4.7 and use that so gcc is always the Apple one.
For ease of using multiple C++ compilers I use macports (or fink or homebrew) which will compile the compilers with the correct patches and also has a port select command to switch between the C++ compilers

Installing GNU Assembler in OSX

No matter how hard I google, I can't seem to find a (relatively) easy-to-follow instruction on how to install the GNU Assembler on a mac.
I know I can use gcc -c (Apple Clang on a Mac) to assemble .s / .S files, but I want to use actual GNU Binutils as.
The GNU assembler cannot (yet) be used to create native object files (of Mach-O format). But you can of course use it to cross-assemble for some non-native object format, if that is what you want.
yasm works on Mac OSX (I got it from Homebrew), and it has a GNU as syntax parser which can be enabled with -p gas (it may be necessary to also add -r gas). It is not 100% complete, but it covers mostly everything. It can output to a variety of object formats (if cross-compiling is necessary), and in my opinion it's pretty cool. You can also use NASM syntax (which is completely supported) using -p nasm (again, -r nasm may be necessary).
Sorry about necroposting, but this is a still-relevant question and I believe that it needs an acceptable answer.
The gnu assembler is already installed on your mac (assuming that you installed the dev tools package). If you want to avoid XCode, you can invoke it from the command line with as, or with the preprocessor by using gcc yourfile.s $(OPTIONS).
Edit: as now points to the clang assembler; at the time this answer was written it pointed to (Apple's build of) the GNU assembler.
Maybe as instead of gas ? If you want to have gas as command invoke this: echo "alias gas=as" >> $HOME/.profile
It was installed on my Mac Lion when i opened the terminal and typed it. It might have been because of MacPorts and/or XCode as mentioned in the comments of a previous answer.

How can I easily install arm-elf-gcc on OS X?

Please let me know if this should be on Server Fault...
I've got some code I want to compile which requires arm-elf-gcc. I'm not an embedded programmer, so all this is new to me. My development machine is a Mac and I use fink pretty often, so I'd love to be able to install it that way. However, fink doesn't know of any package with that name. I see that gnuarm.org has some binaries for OS X but their packages seem to also include a bunch of stuff (e.g. gcc) I already have. Am I correct in believing that I need to install binutils, newlib and a file called t-arm-elf?
MacPorts supports arm-elf-gcc.
$ port search arm-elf
arm-elf-binutils #2.20.51.0.2 (cross, devel)
FSF Binutils for arm-elf cross development
arm-elf-gcc #4.3.2 (cross, devel)
gcc cross-compilers for arm-elf, with newlib runtime library.
arm-elf-gcc3 #3.4.6 (cross, devel)
gcc 3.x cross-compilers for arm-elf, with newlib runtime library.
Found 3 ports.
Once you install MacPorts, all it would take is:
$ sudo port install arm-elf-gcc

Resources