如何在 Xcode 5 中使用最近的 GCC?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19061966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:56:45  来源:igfitidea点击:

How to use a recent GCC with Xcode 5?

xcodemacosgcc

提问by Adam

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.

Apple 完全删除了他们曾经拥有的任何 GCC 支持。有没有办法在 Xcode 5 中使用最近的 GCC(比如 4.8)?换句话说,在 Xcode 中使用 GCC 代替 LLVM。

回答by frogcjn

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

将 GCC 4.8 安装到 Xcode 4.5、Xcode 4.6、Xcode 5.0:

for people who have not install GCC 4.8:

对于尚未安装 GCC 4.8 的人:

install the new version of home-brew

安装新版本的 home-brew

you can find the method how to install on the Internet

你可以在网上找到如何安装的方法

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

将您的 brew 更新到最新版本 ( $brew update)

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

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/)

(可能应该通过 brew 安装 mpc、mpfr 和 gmp,http://solarianprogrammer.com/2013/06/11/compiling-gcc-mac-os-x/ )

2.$brew link gcc48

2.$brew link gcc48

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

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

4.[optional step]:

4.【可选步骤】:

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

别名 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++

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

to /usr/bin/

/usr/bin/

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

【以上4步给没有安装gcc的开发者】

5.make plugin

5.制作插件

1)download a plugin of GCC 4.5 for Xcode

1)为Xcode下载 一个GCC 4.5的插件

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

2)将每个“4.5”更改为“4.8”,将“4_5”更改为“4_8”,文件名,文件内容,

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

除了文件中的“com.apple.compilers.gcc.headers.4_2” GCC 4.5.xcspec

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

您可以保持内容English.lproj不变,并删除Japanese.lproj.

3)in file GCC 4.8.xcspec

3)在文件中 GCC 4.8.xcspec

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

(希望您已经将 的文件名更改GCC 4.5.xcspecGCC 4.8.xcspec

change ExecPath = "...”;

改变 ExecPath = "...”;

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

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)

ExecPath = "/usr/local/Cellar/gcc48/4.8.2/bin/gcc-4.8"(对于通过 brew 安装 gcc-4.8 的人)

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

4)删除文件中的“-Wshorten-64-to-32”部分 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.xcplugininto

6.put编辑GCC 4.8.xcplugin

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

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

7.reopen Xcode.

7.重新打开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

现在,新插件已经为您准备好了。您可以在项目的“Build Settings”的“Compiler for C/C++/Objective-C”中看到您的新 GCC 编译器插件

8.change Build Settings in Xcode project

8.更改Xcode项目中的Build Settings

1)In the projectand targetsettings in Xcode

1)在Xcode的projecttarget设置中

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

将“C/C++/Objective-C 编译器”更改为“GCC 4.8”

2)In the projectsettings

2)在project设置中

delete “CLANG_CXX_LIBRARY" row

删除“CLANG_CXX_LIBRARY”行

回答by Ron

I'm pretty sure the latest versions of gcc can link against Apple's libraries. You can install newer versions of gcc, llvm (and clang), and a lot of other unix applications with Homebrew. Check it out here.

我很确定最新版本的 gcc 可以链接到 Apple 的库。您可以使用 Homebrew 安装更新版本的 gcc、llvm(和 clang)以及许多其他 unix 应用程序。检查它在这里