在 Mac OS X 下編譯 Objective-C 運行時

來源:互聯網
上載者:User

原文地址:http://www.mulle-kybernetik.com/weblog/2011/10/how_to_build_libobjc_for_os_x.html

Max OS X 版本:10.6.8

待編譯運行時版本:437.3

剛剛自己試了一下,可以編譯。

另:文章中提到標頭檔的包含路徑為絕對路徑,這樣不好,可以改為相對路徑,

比如:以 $(SRCROOT) 為參考。

附自己修改的工程打包:http://files.cnblogs.com/Proteas/objc-runtime_10.6.8_437.3.zip

下載後應該可以直接編譯,有問題可以留言。

原文內容:

This builds and links and work for me, but it hasn't been tested much so I don't make any guarantees.

Preparation

Create a directory where to store all the stuff. I chose /usr/local/src/darwin-10.6.8.

prepare
sudo mkdir -p /usr/local/src/darwin-10.6.8
sudo chmod 777 /usr/local/src/darwin-10.6.8

Download and Unpack

Download the following packages:

  • Libc-594.9.5.z
  • dyld-132.13
  • libauto-141.2
  • libclosure-38
  • libdispatch-84.5.5
  • objc4-437.3.
  • xnu-1504.15.3
download
cd /usr/local/src/darwin-10.6.8/
curl -O http://www.opensource.apple.com/tarballs/Libc/Libc-594.9.5.tar.gz
curl -O http://www.opensource.apple.com/tarballs/dyld/dyld-132.13.tar.gz
curl -O http://www.opensource.apple.com/tarballs/libauto/libauto-141.2.tar.gz
curl -O http://www.opensource.apple.com/tarballs/libclosure/libclosure-38.tar.gz
curl -O http://www.opensource.apple.com/tarballs/libdispatch/libdispatch-84.5.5.tar.gz
curl -O http://www.opensource.apple.com/tarballs/objc4/objc4-437.3.tar.gz
curl -O http://www.opensource.apple.com/tarballs/xnu/xnu-1504.15.3.tar.gz

tar xfz Libc-594.9.5.tar.gz
tar xfz dyld-132.13.tar.gz 
tar xfz libauto-141.2.tar.gz
tar xfz libclosure-38.tar.gz 
tar xfz libdispatch-84.5.5.tar.gz
tar xfz objc4-437.3.tar.gz 

You can also manually download stuff fromhttp://www.opensource.apple.com/release/mac-os-x-1068/.

Installation of Headers

Copy the needed headere into /usr/local/include/darwin-10.6.8. The versioning of the destination directory is important, otherwise you might get some strange bugs later on in life.

install
sudo mkdir -p /usr/local/include/darwin-10.6.8
sudo chmod 777 /usr/local/include/darwin-10.6.8
cd /usr/local/include/darwin-10.6.8
mkdir libkern
mkdir System
mkdir System/i386
mkdir System/ppc
mkdir System/machine
mkdir mach-o

cd /usr/local/src/darwin-10.6.8

# find . -name "OSCrossEndian.h"
# find . -name "pthread_machdep.h"
# find . -name "dyld_priv.h"
# find . -name "cpu_capabilities.h"
# find . -name Block_private.h 
# find . -name auto_zone.h

cp ./xnu-1504.15.3/libkern/libkern/OSCrossEndian.h /usr/local/include/darwin-10.6.8/libkern/
cp ./Libc-594.9.5/pthreads/pthread_machdep.h /usr/local/include/darwin-10.6.8/System/
cp ./dyld-132.13/include/mach-o/dyld_priv.h /usr/local/include/darwin-10.6.8/mach-o/
cp ./xnu-1504.15.3/osfmk/i386/cpu_capabilities.h /usr/local/include/darwin-10.6.8/System/i386/
cp ./xnu-1504.15.3/osfmk/ppc/cpu_capabilities.h /usr/local/include/darwin-10.6.8/System/ppc/
cp ./xnu-1504.15.3/osfmk/machine/cpu_capabilities.h /usr/local/include/darwin-10.6.8/System/machine/
cp ./libclosure-38/Block_private.h /usr/local/include/darwin-10.6.8/
cp ./libauto-141.2/auto_zone.h /usr/local/include/darwin-10.6.8/

Change the Xcode Project of objc

open objc4-437.3/*.xcodeproj

Open the project settings in Xcode and set:

  • HEADER_SEARCH_PATHS=/usr/local/include/darwin-10.6.8 $(inherited) for all Configurations
  • GCC_PREPROCESSOR_DEFINITIONS=$(inherited) PRIVATE for Debug and
  • GCC_PREPROCESSOR_DEFINITIONS=$(inherited) NDEBUG PRIVATE for Release

But this isn't good enough yet. Fix the objc target settings by prefixing $(inherited) toHEADER_SEARCH_PATHS thusly

  • HEADER_SEARCH_PATHS = $(inherited) $(DSTROOT)/usr/include/** $(DSTROOT)/usr/local/include/** $(CONFIGURATION_BUILD_DIR)/usr/include/** $<(CONFIGURATION_BUILD_DIR)/usr/local/include/**

Then you should go into the objc target's Compile sources settings and move the fileobjc-probes.d to the top, so that it gets compiled first.

And now it should build and link without errors.

Go ahead and trash your system with the debug linked version

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.