Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a recent GCC with Xcode 5?

Tags:

xcode

macos

gcc

Apple completely removed whatever GCC support they used to have. Is there any way to use a recent GCC (say 4.8) with Xcode 5? In other words, to use GCC in place of LLVM within Xcode.

like image 972
Adam Avatar asked Sep 28 '13 00:09

Adam


People also ask

Does Xcode use gcc?

The LLVM Project Xcode 4 exploits this modular approach to provide features such as improved syntax highlighting and to suggest fixes to common coding errors. As of writing GCC remains the default compiler for Xcode 3 but with the release of Xcode 4 the default compiler for new projects has changed to LLVM-GCC.

Is gcc already installed on Mac?

Often times, you need c or gcc compiler to compile open source projects in Mac OS X. The problem is Mac OS X doesn't install the gcc compiler by default. In terminal, type “ gcc “, you will get message “command not found”.

What is clang vs gcc?

Clang is designed as an API from its inception, allowing it to be reused by source analysis tools, refactoring, IDEs (etc) as well as for code generation. GCC is built as a monolithic static compiler, which makes it extremely difficult to use as an API and integrate into other tools.


1 Answers

install GCC 4.8 into Xcode 4.5, Xcode 4.6, Xcode 5.0:

for people who have not install GCC 4.8:

install the new version of home-brew

you can find the method how to install on the Internet

update your brew to the latest version ($brew update)

1.brew install gcc48 --enable-all-languages

(may should install mpc, mpfr and gmp through brew, http://solarianprogrammer.com/2013/06/11/compiling-gcc-mac-os-x/)

2.$brew link gcc48

3.backup g++,gpp,c++,cpp,c++ in /usr/bin/

4.[optional step]:

alias g++-4.8,gpp-4.8,c++-4.8,cpp-4.8,c++-4.8

from /usr/local/Cellar/gcc48/4.8.2/bin/g++

to /usr/bin/

[above 4 steps for the developer who have not install gcc]

5.make plugin

1)download a plugin of GCC 4.5 for Xcode

2)change every "4.5" to "4.8", "4_5" to "4_8", the file names, the file contents,

except "com.apple.compilers.gcc.headers.4_2” in the file GCC 4.5.xcspec.

you can remain contents in English.lproj unchanged, and delete Japanese.lproj.

3)in file GCC 4.8.xcspec

(hope you have already change the file name of GCC 4.5.xcspec to GCC 4.8.xcspec)

change ExecPath = "...”;

to ExecPath = "/usr/local/bin/gcc-4.8"

or ExecPath = "/usr/local/Cellar/gcc48/4.8.2/bin/gcc-4.8" (for the people who install gcc-4.8 by brew)

4)delete “-Wshorten-64-to-32” part in file GCC 4.8.xcspec

{
    Name = "GCC_WARN_64_TO_32_BIT_CONVERSION";
    Type = Boolean;
    DefaultValue = NO;
    CommandLineArgs = {
        YES = (
            "-Wshorten-64-to-32",
        );
        NO = ();
    };
    AppearsAfter = "GCC_WARN_PROTOTYPE_CONVERSION";
    Category = Warnings;
    CommonOption = NO;
    DisplayName = "Implicit Conversion to 32 Bit Type";
    Description = "Warn if a value is implicitly converted from a 64 bit type to a 32 bit type.
    [GCC_WARN_64_TO_32_BIT_CONVERSION, -Wshorten-64-to-32]";
}

6.put edited GCC 4.8.xcplugin into

/Applications/Xcode.app/Contents/Plugins/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/

7.reopen Xcode.

Now, the new plugin has already prepared for you. You can see your new GCC compiler plugin in the "Compiler for C/C++/Objective-C" of "Build Settings" of your project

8.change Build Settings in Xcode project

1)In the project and target settings in Xcode

change "Compiler for C/C++/Objective-C" to "GCC 4.8"

2)In the project settings

delete “CLANG_CXX_LIBRARY" row

like image 181
frogcjn Avatar answered Sep 28 '22 17:09

frogcjn