Hint for Installing gcc cross compilers on Mac...

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Hint for Installing gcc cross compilers on Mac...

Postby westfw » Thu Feb 09, 2012 8:16 pm

Installing gcc (or other open source software packages) on a Mac can be tricky. If it's something supported by a package manager, like Fink/FinkCommander, you're all set. But if not...

The problem seems to be that the Mac Development environment (via XCode) includes a rather old (4.2) and non-standard version of gcc (llvm-gcc?._ In theory, you can use this to compile open source software. But many newer OSSW packages are dependent on libraries (mpc, mpfr, gmp, etc) and may require newer versions than those that come with XCode. You can install newer libraries, but they should up in a different path than the native gcc expects, and may conflict with Mac things. You should be able to specify alternate paths for some libraries, but then you don't know for sure that they're compatible with other libraries whose path can't be changed. And it doesn't necessarily solve all the problems.

In my case, I was trying to install avr-gcc 4.7 (!experimental!), and couldn't get past a bunch of "library is incompatible architecture" errors in the configure/build, no matter what I did. Various people have reported similar problems, but I couldn't find an explanation that yielded a general fix. At least not for my combination of SW versions and package managers...

What I ended up doing was to have fink install a 2nd copy of gcc (for Mac) - v4.6 in this case. Fink goes ahead and puts this in the same directories/paths as the other Fink-managed apps/libraries, and installs some basic library support of the correct versions as well. Then, you can "export CC=/sw/bin/gcc-fsf-4.6" before trying to configure/compile your source. This seems to make things go a lot smoother, so I thought I'd share the idea...
(and it's only about a gigabyte of extra compilers/etc!)
User avatar
westfw
 
Posts: 1321
Joined: Fri Apr 27, 2007 12:01 pm
Location: SF Bay area

Re: Hint for Installing gcc cross compilers on Mac...

Postby scott-42 » Mon Feb 13, 2012 12:03 am

Xcode generally links its version of gcc to /usr/bin/gcc and the current one is indeed a non-standard version:
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)

I've been able to just put everything else in the /usr/local tree where I currently have a version of avr-gcc and avrdude.
avr-gcc (GCC) 4.6.1

I generally try to build everything from source so I've picked up the habit of /usr/local being all the open source projects and other code I've downloaded over the years.
scott-42
 
Posts: 123
Joined: Mon May 30, 2011 9:46 am
Location: Santa Clara, CA

Re: Hint for Installing gcc cross compilers on Mac...

Postby avenue33 » Wed Feb 15, 2012 3:49 am

@scott-42

Very interesting.

This could save endless makefiles as those I've wrote for my Arduino and chipKIT on Xcode 4.2: Project and Templates project.

Because I'm dealing with both Arduino boards and chipKIT boards, I need to have both avr-gcc and pic32-gcc installed.

How to install both so Xcode could use them —obviously, one at a time and the right one?

Thanks!
avenue33
 
Posts: 70
Joined: Sat Dec 11, 2010 7:42 am

Re: Hint for Installing gcc cross compilers on Mac...

Postby scott-42 » Wed Feb 15, 2012 11:49 am

avenue33 wrote:How to install both so Xcode could use them —obviously, one at a time and the right one?

I'd install the complete avr-gcc and pic32-gcc packages in /usr/local/ and then in Xcode just point the C compiler to the /usr/local/bin/avr-gcc binary. You will have to set the headers path and possibly the library path, but it should be able to compile any C source and generate an object file. Check out the "Build Rules" tab in your project file where you can override the C compiler and the linker. I haven't tried this before but I would think that you could just point to the other compiler/linker and drop in any needed libs and it should work.

I'd be neat if you created a ".framework" for the avr stuff too to encapsulate the needed libs and headers then you could just drop that one in. There are several webpages on the net about how to make them, not too hard.
scott-42
 
Posts: 123
Joined: Mon May 30, 2011 9:46 am
Location: Santa Clara, CA


Return to Microcontrollers

Who is online

Users browsing this forum: No registered users and 0 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [107]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[31]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[70]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[111]
 
Wireless[14]
Cables[62]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]