GCC as main compiler on 10.9

Hello, I have been unable to succesfully install gcc 4.8 or 4.9 on Mac OS X Mavericks. Nor i can use clang anymore as well. I tried installing GCC with homebrew and followed some instructions to add plugin for XCode but it seems it broke both of the compilers. Mainly i want GCC because clang won't allow me to have definitions in separate cpp file. I get error that compiler can't 'read' symobls, but when i put definition in header file everything works fine.

OS X Mavericks (10.9.2)

Posted on Mar 4, 2014 8:57 AM

Reply
19 replies

Mar 4, 2014 11:24 AM in response to etresoft

for example i have a simple class

[code]

in sample.h

#include <iostream>

class Sample {

int i;

public:

// ....

inline void f1();

void f2;

};

[/code]

in sample.cpp

[code]

#include "sample.h"


inline void Sample::f1() {

i=1;

}


void Sample::f2() {

i = 2;

}

[/code]


it won't allow me to do that since 10.9.1 and i was forced to use windows for Uni excercises, and I'm already annoyed that i have to use windows for it.

this is what i get by compiler:

ld: symbol(s) not found for architecture x86_64

Mar 4, 2014 7:28 PM in response to colask8

Your sample has a syntax error. You must say "void f2();" to define a method. You also didn't include what the error is. Symbol(s) not found? What symbols? After fixing that syntax error, your code works fine here. Are you using the right compiler variant? Clang is just like GCC. If you want to compile C++, you need to do clang++.

Mar 5, 2014 5:12 AM in response to colask8

Xcode automatically configures the compiler correctly for your source language. GCC is dead, at least on the Mac. People are starting to switch to Clang on other platforms as well. GCC became popular because it was free, of terms of cost rather than politics. Clang is just as inexpensive but has no free software politics that restrict its design. Plus, with it's far superior error messages, Clang should be a natural choice for anyone learning C++. If you want to use GCC via Homebrew, you will have to ask Homebrew for support. If you want to use GCC, you will have to ask GNU for support and they have never supported the Mac. Their lack of support was the driving factor for the Apple's development of Clang. GNU will suggest that you use Linux if you want to use GCC and they are right.

Mar 8, 2014 11:02 AM in response to colask8

colask8 wrote:


And so on, i have found that clang has bugs as ****.


Such as? Clang has a very active development community. The possibility that it would have any bug that could impede the progress of a developer ranges from virtually zero for experts to absolute zero for beginners.


So that might be the reason why i wanted to use gcc, but i see as you stated that they dont want to get involved with apple anymore.


You are unsure about why you wanted to use GCC?


GNU never wanted to be involved with Apple. It was only a bug in their licensing that allowed Apple to use GCC. When GNU fixed that bug with version 3 of the GPL, Apple started heavy developlent of LLVM and, eventually, CLang.


So if you know the way to update to clang 3.5? Because i cannot seem to find a proper tutorial for it. Thank you 🙂


There are no such tutorials. If you want to install a private build of Clang, or GCC for that matter, just do it. It is not a simple task and I doubt you will find any tutorials. That is something that the developers of those compilers might do.


What I suggest you do is clearly explain what you are trying to do, at a very high level. What code are you trying to compile that the built-in compiler in Xcode cannot compile?

Aug 11, 2014 2:26 PM in response to etresoft

It's not quite true that clang can do everything gcc can.


To quote the clang user manual: "clang does not support the gcc extension that allows variable-length arrays in structures."


Not a problem most of the time, but it's a problem for me now, since I need to compile the code of a colleague that used variable-length arrays. Clang gives me errors like "error: variable length array of non-POD element type" for most of the files.


Perhaps I'm being pedantic. You may still be right as a general rule, and in the sense that most people who ask how to use gcc on a mac don't really need to.

Aug 11, 2014 2:45 PM in response to r.r.p.

And people who rely on GCC extensions tend to get burned by them. There is a reason why there are language standards. It is annoying when a compiler doesn't implement everything, but that can be worked around. But when a compiler implements too much, there is no workaround for that. I used to hear the refrain "...but it works fine on Linux" often during the Codewarrior days and now it is starting up again. This time, GCC is the one annoying people.

Aug 12, 2014 8:05 AM in response to etresoft

For sure. I've learned my lesson about gcc extensions and won't put anyone using my code in the position that my colleague put me in. From now on I think I'll use the -ansi and -pedantic-errors flags to make sure I'm adhering to the standards.


So while I have had to install gcc on mac, I regard that as being due to a deficiency of the code I'm compiling rather than of clang.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

GCC as main compiler on 10.9

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.