Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

laredotornado

macrumors newbie
Original poster
Mar 29, 2012
2
0
Hi,

I'm using Mac OSX Lion. I just installed XCode, Version 4.3.2 (4E2002). I did this because I wasn't able to build a wget tarball. That configure died because I didn't have a gcc or cc compiler. I thought installing XCode was supposed to install those components. Is that wrong? How do I install C compilers on my Mac?

Thanks, - Dave
 

dylanweber

macrumors newbie
Jul 14, 2009
28
0
USA
I believe that installing Xcode does install GCC.
It's required for Xcode to work, anyways, so it's a logical guess for them to both be installed at once.
 

mfram

Contributor
Jan 23, 2010
1,307
343
San Diego, CA USA
It has the compilers, just not the command line tools by default. You need to go into your Xcode preferences and tell it to download the command line tools. It's on the same panel that lets you install the reference docs locally.
 

laredotornado

macrumors newbie
Original poster
Mar 29, 2012
2
0
mfram, Indeed, When I went to Preferences -> Downloads, I found the Command Line Tools "Install" button. Installing that allowed me to access gcc from the command line. Alas, now I can begin my world domination.

Thanks, - Dave
 

thundersteele

macrumors 68030
Oct 19, 2011
2,984
9
Switzerland
Just to make it clear: Xcode does not install gcc (the gnu C compiler).

Xcode does install Apples own C-compiler, called llvm. Llvm is not fully compatible with all programs written for gcc, so use at your own risk.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Just to make it clear: Xcode does not install gcc (the gnu C compiler).

Xcode does install Apples own C-compiler, called llvm. Llvm is not fully compatible with all programs written for gcc, so use at your own risk.

Clang is fully compatible with the C standard and most of the gcc extensions which is what counts. The use at your own risk remark should be left for anyone using compiler specific extensions not in the C standard. Clang is the default compiler in both OS X and freeBSD 9.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
But as noted gcc is not installed in any way, shape or form and is only a 'link' to llvm-gcc-4.2.

Yes, but llvm-gcc is the gcc front end on top of a llvm code generator. There are two interesting WWDC 2010 session videos about this 312 and 313.
 

thundersteele

macrumors 68030
Oct 19, 2011
2,984
9
Switzerland
Clang is fully compatible with the C standard and most of the gcc extensions which is what counts. The use at your own risk remark should be left for anyone using compiler specific extensions not in the C standard. Clang is the default compiler in both OS X and freeBSD 9.

Yes, formally what you are saying is right, I guess.

I had the following issue with GSL (a scientific/math C++ library):
It compiled successfully with GSL, and ran through a large number of test routines that were supplied together with GSL, before eventually one test failed (i.e. the result of a calculation was not what it was supposed to be). Installed gnu-gcc and re-compiled, and the error went away.
Now, I never went back to explore this. Maybe the testing routine was written using non-standard C(++), of maybe some part of the library is non-standard C++. Still, at the end of the day, it's a risk to compile it with LLVM, and the easiest way to avoid possible errors is to use gnu-gcc to compile programs written for it.

Maybe this is a very small, isolated issue, and certainly not a problem for native OSX software. The OP had problems building wget, we'll see if LLVM does the job for that program.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Maybe the testing routine was written using non-standard C(++), of maybe some part of the library is non-standard C++. Still, at the end of the day, it's a risk to compile it with LLVM, and the easiest way to avoid possible errors is to use gnu-gcc to compile programs written for it.

Before you isolate the problem and find that non standard gcc extensions are used and are the sole reason that is not supported by clang, what you say is just guessing. Considering that the complete freeBSD 9 is built with Clang I'd say it's not a risk.

Lastly llvm-gcc IS gcc with the llvm backend.
 

thundersteele

macrumors 68030
Oct 19, 2011
2,984
9
Switzerland
Before you isolate the problem and find that non standard gcc extensions are used and are the sole reason that is not supported by clang, what you say is just guessing. Considering that the complete freeBSD 9 is built with Clang I'd say it's not a risk.
.

Yes, I'm just guessing. Unfortunately I neither have the time nor the C++ skills to start tracking down this issue.
If you're interested, google "GSL LLVM" gives a few related bug reports (not by me), and interestingly, also one report of a successful build and test using LLVM on a Debian machine.

I'm not claiming that there is a problem with llvm btw.
 

Mac_Max

macrumors 6502
Mar 8, 2004
404
1
Yes, formally what you are saying is right, I guess.

I had the following issue with GSL (a scientific/math C++ library):
It compiled successfully with GSL, and ran through a large number of test routines that were supplied together with GSL, before eventually one test failed (i.e. the result of a calculation was not what it was supposed to be). Installed gnu-gcc and re-compiled, and the error went away.
Now, I never went back to explore this. Maybe the testing routine was written using non-standard C(++), of maybe some part of the library is non-standard C++. Still, at the end of the day, it's a risk to compile it with LLVM, and the easiest way to avoid possible errors is to use gnu-gcc to compile programs written for it.

Maybe this is a very small, isolated issue, and certainly not a problem for native OSX software. The OP had problems building wget, we'll see if LLVM does the job for that program.

Not sure if it would have made a difference in your case, but I think its worth noting that GCC defaults to C89 (with partial C99 support & GNU extensions) & C++98 with some (most?) of 03 and Clang/LLVM defaults to C99 and C++98/Some C++03 with most of C++11 and probably most of the GNU extensions.

What I'm getting at is that it could have still been valid/standard C++ but an edge case where they were different/conflicting standards that didn't mesh right between the compilers and their default settings/standards. There are also the chance that they used a GNU extension that's not supported (or a MS extension that's not 100% compatible for that matter... see MS's 10,000 different C String copy routines...). Listening to various talks from the Clang development team at Google it seems like they are trying to make available a good level of compatibility with GCC. As such, you (or anyone else with similar issues) could try compiling using Clang and the gnu89 or similar compilation option to remedy conflicts between the two. Granted this is something that the gcc front end might do already but there is a chance that it just needs some additional tweaking or a newer version of Clang.

Also another general issue I've heard of before (in a passing conversation) was one where the programmer was dealing with porting some nasty, hacky (by today's standards), & edge case filled C++ library that only really compiled well against GCC 2.8 and died on newer versions of any compiler. I think he said that was one of the last versions of GCC to not be fully ISO C++ compliant or something along those lines.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
Now, I never went back to explore this. Maybe the testing routine was written using non-standard C(++), of maybe some part of the library is non-standard C++. Still, at the end of the day, it's a risk to compile it with LLVM, and the easiest way to avoid possible errors is to use gnu-gcc to compile programs written for it.

Want to bet that the issue is in your code?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.