How to use a recent GCC with Xcode 5?

后端 未结 2 1945
闹比i
闹比i 2020-12-05 03:51

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 wit

相关标签:
2条回答
  • 2020-12-05 03:59

    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.

    0 讨论(0)
  • 2020-12-05 04:09

    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

    0 讨论(0)
提交回复
热议问题