2013年8月16日 星期五

[OSX] 使用 MacPorts 指定參數編譯 Source code 筆記 @ Mac 10.8

最近在開發 OSX app 時,常常會碰到一些 library 找不到或需要客制化的問題,例如以 clang++ 與 -stdlib=libc++ -std=c++11 等相關參數的指定。

以 wxWidgets30 為例,若單純用 sudo port install wxWidgets30 時,預設會直接安裝已編好的 binary 檔案,若想要強制 source code 編譯,則用 sudo port install -s wxWidgets30。

但從 source code 編譯時,有想要下一些 configure 參數咧?那就用 configure.args 吧!

$ sudo port install -s wxWidgets30 configure.args="--with-osx_cocoa --with-libiconv=no --with-macosx-sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk --with-macosx-version-min=10.7 --disable-shared --disable-debug"

如此一來,看 log 時可以找到它在 configure 真的下了這些參數。那 CXXFLAGS 、LDFLAGS 呢?一樣用 configure.cxxflags 和 configure.ldflags 處理。

然而,有時 configure.cxxflags 沒有滲透很深,那就改用 configure.cxx="clang++ -std=c++11 -stdlib=libc++" 來處理吧 :P

故以 wxWidgets30 為例,想要編出支援 c++11 的方式(可以先用 port install wxWidgets30 補完相依性後,再用 port uninstall wxWidgets30 後,再開始用 port -s install wxWidgets30):

$ port info wxWidgets30
wxWidgets30 @2.9.5_2 (graphics, devel)
Variants:             aui, debug, monolithic, [+]sdl, stdlib, universal

Description:          wxWidgets is a mature open-source cross-platform C++ GUI framework for Mac OS, Unix, Linux, Windows. It can
                      make use of a variety of native widget sets as well as its own widget set: Mac OS, GTK+, Motif, WIN32.
                      wxWidgets will even run on embedded systems using Linux and X11.
Homepage:             http://www.wxwidgets.org/

Library Dependencies: jpeg, tiff, libpng, zlib, libiconv, expat, libsdl, libsdl_mixer
Conflicts with:       wxgtk, wxWidgets
Platforms:            darwin
License:              wxwidgets-3.1
Maintainers:          jwa@macports.org, mojca@macports.org

$ sudo port install -s wxWidgets30 configure.cc=clang configure.cxx="clang++ -std=c++11 -stdlib=libc++" configure.cxxflags="-std=c++11 -stdlib=libc++ -O2" configure.objcxxflags="-std=c++11 -stdlib=libc++ -O2"

沒有留言:

張貼留言