Code Monkey home page Code Monkey logo

xcodelegacy's Introduction

XcodeLegacy

Legacy components for XCode 4-8 (deprecated compilers and Mac OS X SDKs).

Home page: https://github.com/devernay/xcodelegacy

Description

Many components were removed in recent versions of Xcode, the most notable being the Mac OS X 10.6 SDK, which is required to build software using the Carbon API (such as wxWidgets 2.8).

I made the script XcodeLegacy.sh to extract these components (the links work if you sign in to Apple Developer first) from Xcode 3.2.6 (10.4, 10.5 and 10.6 SDKs, PPC assembler, GCC 4.0 and 4.2, LLVM-GCC 4.2), Xcode 4.6.3 (10.7 SDK), Xcode 5.1.1 (10.8 SDK), Xcode 6.4 (10.9 and 10.10 SDKs), Xcode 7.3.1 (10.11 SDK) and install them in Xcode 4-8:

  • GCC 4.0, GCC 4.2 and LLVM GCC 4.2 compilers
  • GCC 4.0, GCC 4.2 and LLVM GCC 4.2 Xcode plugins
  • PPC assembler
  • Mac OS X SDK 10.4u, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11

Note: There may be similar tips to compile for older iOS (not Mac OS X) versions, but I don't develop for iOS. However, if you want to enhace the XcodeLegacy script to also include those components, I'll gladly integrate your modifications.

Download

XcodeLegacy.sh (previous versions: 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0)

GitHub repository

Usage

Open a Terminal application, change to the directory where XcodeLegacy.sh, and make it executable, as in:

cd path/to/xcodelegacy
chmod +x XcodeLegacy.sh

Execute the script by typing ./XcodeLegacy.sh <arg>. The script takes one argument, which can be "buildpackages" (to extract components from the legacy Xcode downloads to the current directory), "install" (to install the components in Xcode 4-8), "cleanpackages" (to delete the extracted components from the current directory), "uninstall" (to uninstall the components from Xcode 4-8).

With the "install" or "uninstall" arguments, the script uses sudo to become root, and will thus ask for your password. Please check the script contents before executing it.

Optionally, one of the following options can be passed as the first argument to XcodeLegacy.sh, to limit its operation:

  • -compilers : only install the gcc and llvm-gcc compilers, as well as the corresponding Xcode plugins
  • -osx104 : only install Mac OSX 10.4 SDK
  • -osx105 : only install Mac OSX 10.5 SDK
  • -osx106 : only install Mac OSX 10.6 SDK
  • -osx107 : only install Mac OSX 10.7 SDK
  • -osx108 : only install OSX 10.8 SDK
  • -osx109 : only install OSX 10.9 SDK
  • -osx1010 : only install OSX 10.10 SDK
  • -osx1011 : only install OSX 10.11 SDK

Using the older SDKs

To use any of the older SDKs, you should:

  • compile and link with the options -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk
  • set the environment variable MACOSX_DEPLOYMENT_TARGET to the proper value (e.g. 10.5) - this should be redundant with the -mmacosx-version-mincompiler option, but older compilers do not seem to pass this option to the linker.

For example:

env MACOSX_DEPLOYMENT_TARGET=10.6 clang -arch i386 -arch x86_64 -mmacosx-version-min=10.6 -isysroot /Developer/SDKs/MacOSX10.6.sdk main.c -o main

Using the older compilers

Links to the compilers are installed in /usr/bin (or /usr/local/bin on OS X 10.11 El Capitan and later): gcc-4.0 g++-4.0 gcc-4.2 g++-4.2 llvm-cpp-4.2 llvm-g++-4.2 llvm-gcc-4.2.

GCC 4.0, GCC 4.2 and LLVM GCC 4.2 cannot compile for OS X 10.10 or newer.

PowerPC architectures (ppc, ppc7400, ppc970, ppc64) cannot be linked for OS X 10.7 or newer (they would be useless anyway, since PowerPC CPUs were only supported up to 10.5).

Note on Xcode versions

Here are the latest versions of Xcode that are known to /run/ on each OS X version (the links work if you sign in to Apple Developer first):

More information about the compilers included in each version of Xcode can be found on the MacPorts Wiki.

Linking for x86_64 on Xcode 4.4 and later

If targetting 10.6, the following error may appear:

 For architecture x86_64: Undefinedsymbols

 "_objc_retain", from: referenced

     In libarclite_macosx.a ___ARCLite__load (arclite.o)

    (youmeant: _objc_retainedObject maybe)

Symbol not (s) found for architecture x86_64 ld:

Error: linker command failed with exit code use 1 (-v to seeinvocation clang:)

Solution: in the Build Setting of the Project (not for the Target), set the setting "Implicitly Link Objective-C Runtime Support" to NO.

Linking for ppc on Xcode 7.3 and later

Recent versions of Xcode and ld added several options. These are taken care of by the stub ld script (notably -object_path_lto xxx, -no_deduplicate, -dependency_info xxx), but after an Xcode upgrade new errors may appear, like:

Running ld for ppc ...
ld: unknown option: -object_path_lto

There are two possible solutions:

  • check in the file /Applications/Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/Ld.xcspec if there is an Xcode setting to disable that option (LD_LTO_OBJECT_FILE in the above case)
  • edit /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld to prune the culprid option (and its argument)

Known bugs (and fixes) in OS X SDKs

Recent GCC versions cannot build universal binaries

The GCC in Apple SDK is actually a small binary that lauches several compilers and merges the results (see driverdriver.c). The same executable can be compiled for recent GCC versions too, see devernay/macportsGCCfixup on github.

bad_typeid dyld Error on Leopard (10.5)

This is a bug in the 10.6 (and later) SDKs, which can be easily fixed:

code compiled with g++ > 4.2.1 crashes with "pointer being freed not allocated"

The problem comes from the fact that some system frameworks load the system libstdc++, which results in incompatible data structures.

After exploring various options (install_name_tool, rpath, etc.), the only solution is to set the environment variable DYLD_LIBRARY_PATH to the path of a directory where you only put a symbolic link to the newest libstdc++ from GCC (libstdc++ is guaranteed to be backward-compatible, not other libraries).

If you are building an application bundle, you should replace your executable by a small executable that sets the environment variable DYLD_LIBRARY_PATH. It can be a script (see below), or a binary (better, because it handles spaces in arguments correctly).

The setdyld_lib_path.c source code can be compiled to act as a "launcher" for your binary that correctly sets the DYLD_LIBRARY_PATH variable. See the full instructions at the top of the source file.

An alternate solution, using a shell-script (doesn't handle spaces in arguments): http://devblog.rarebyte.com/?p=157

Other references:

License

This script is distributed under the Creative Commons BY-NC-SA 3.0 license.

History

  • 1.0 (08/10/2012): First public version, supports Xcode up to version 4.6.3
  • 1.1 (20/09/2013): Xcode 5 removed llvm-gcc and 10.7 SDK support, grab them from Xcode 3 and 4
  • 1.2 (03/02/2014): Xcode 5 broke PPC assembly and linking; fix assembly and grab linker from Xcode 3
  • 1.3 (07/10/2014): Xcode 6 removed 10.8 SDK, grab it from Xcode 5.1.1
  • 1.4 (21/08/2015): Xcode 7 removed 10.9 and 10.10 SDKs, grab them from Xcode 6.4
  • 1.5 (15/10/2015): Fixes for OS X 10.11 El Capitan (nothing can be installed in /usr/bin because of the sandbox)
  • 1.6 (11/11/2015): Fix buildpackages, fix /usr/bin/gcc on recent OS X, fix download messages
  • 1.7 (05/04/2016): Xcode 7.3 disables support for older SDKs, fix that
  • 1.9 (16/09/2016): Xcode 8 dropped 10.11 SDK, get it from Xcode 7.3.1
  • 2.0 (02/05/2017): Xcode 8 cannot always link i386 for OS X 10.5, use the Xcode 3 linker for this arch too. Force use of legacy assembler with GCC 4.x.

xcodelegacy's People

Contributors

devernay avatar ericfromcanada avatar raxoft avatar inspector-g avatar jaesgk avatar nickwww avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.