標籤:
前言
之前已經在MacOS下搭建好了OpenWrt的編譯環境,沒想到更新到最新的官方Trunk之後,噩夢就此開始。現將思考過程以及應對方法做個記錄。
背景知識
OpenWrt推薦用MacPorts來搭建MacOS中的相關工具。MacOS內建了gcc,版本資訊如下:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)Target: x86_64-apple-darwin13.4.0Thread model: posix
如果安裝了mp-gcc49,則會在/opt/local/bin目錄下建立gcc,其版本資訊如下:
gcc (MacPorts gcc49 4.9.2_1) 4.9.2Copyright (C) 2014 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
在搭建編譯環境時,可能需要兩個gcc切換(一個出錯以後,切換另一個使用)。
首先,請確保安裝了如下macports工具庫
sudo port install coreutils e2fsprogs ossp-uuid asciidoc binutils bzip2 fastjar flex getopt gtk2 intltool jikes hs-zlib openssl p5-extutils-makemaker python26 subversion rsync ruby sdcc unzip gettext libxslt bison gawk autoconf wget gmake ncurses findutils gnutar mpfr libmpc gcc49
說明:mpfr libmpc非必須,系統在編譯gcc時,會自動從源碼編譯這兩個庫,但如果用llvm-gcc編譯時間,可能會出現如下錯誤:
checking for the correct version of the gmp/mpfr/mpc libraries... noconfigure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
問題描述問題1:
Undefined symbols for architecture x86_64: "_iconv", referenced from: convert_using_iconv(void*, unsigned char const*, unsigned long, _cpp_strbuf*) in libcpp.a(charset.o) (maybe you meant: __Z14cpp_init_iconvP10cpp_reader, __cpp_destroy_iconv ) "_iconv_close", referenced from: __cpp_destroy_iconv in libcpp.a(charset.o) __cpp_convert_input in libcpp.a(charset.o) "_iconv_open", referenced from: init_iconv_desc(cpp_reader*, char const*, char const*) in libcpp.a(charset.o)ld: symbol(s) not found for architecture x86_64
碰到此種情況,說明你用的是mp-gcc49編譯的,在這個地址有關於此錯誤的描述
http://stackoverflow.com/questions/12619600/libiconv-and-macos
macports的libiconv與mac系統的不一致,此時需要做如下修改:
1.切換到mac系統的gcc
2.進入staging_dir/host/usr,建立並進入lib目錄,建立/opt/local/lib/中所有libiconv開頭的符號連結
問題2:
Undefined symbols for architecture x86_64: "_ERR_remove_thread_state", referenced from: _rsa_sign in rsa-sign.old: symbol(s) not found for architecture x86_64
這個問題最為奇怪,網上沒有任何地方有對此問題的說明,經過仔細檢查錯誤資訊,發現在錯誤資訊之前,有一個
HOSTLDFLAGS=“”
在mkimage的Makefile中,修改
#HOSTLDFLAGS="$(HOST_STATIC_LINKING)"define Host/Compile<span style="white-space:pre"></span>$(MAKE) -C $(HOST_BUILD_DIR) defconfig<span style="white-space:pre"></span>$(MAKE) -C $(HOST_BUILD_DIR) <span style="white-space:pre"></span>HOSTLDFLAGS="-L/opt/local/lib" <span style="white-space:pre"></span>tools-onlyendef
實際上HOSTLDFLAGS在include/host-build.mk中定義:
ifneq ($(HOST_OS),Darwin) ifeq ($(CONFIG_BUILD_STATIC_TOOLS),y) HOST_STATIC_LINKING = -static endifendi
如果不是Darwin(MacOS),則設定為-static,否則,否則,否則呢!?就不設定任何的值。可以修改此處為:
ifneq ($(HOST_OS),Darwin) ifeq ($(CONFIG_BUILD_STATIC_TOOLS),y) HOST_STATIC_LINKING = -static endifelse HOST_STATIC_LINKING = -L/opt/local/libendif
總結
在第二個問題的處理上糾纏了很久。看來在MacOS下搭建OpenWrt的編譯環境確實是一個比較“蛋疼”的舉動
Mac OS下搭建OpenWrt編譯環境記錄(針對官方最新2015.01.20之trunk)