gomingw構建記錄(僅runtime)

gomingw構建記錄(僅runtime)
2011年03月07日
  注意,不完整編譯,僅8g、8l和runtime.a
  1. gomingw
  Go MinGW Builds Win32 (experimental) build of release 2011-03-07.1 http://code.google.com/p/gomingw/ 2. MSYS | MinGW MinGW - Minimalist GNU for Windows * gcc version 3.4.5 (mingw-vista special r3) * GNU Make 3.81 http://sourceforge.net/projects/mingw/ 或者用這個(未測試) https://bitbucket.org/jpoirier/go_mingw/downloads
  3. 編譯的額外工具
  a. 需要以下工具和庫(注意,依賴於mingw的運行時dll,故需要msys/mingw纔可運行) * Ed - A line-oriented text editor (ed.exe,依賴於Regex) http://gnuwin32.sourceforge.net/packages/ed.htm http://www.gnu.org/software/ed/ed.html * LibIntl for Windows (libintl3.dll) http://gnuwin32.sourceforge.net/packages/libintl.h tm * Regex for Windows (regex2.dll) http://gnuwin32.sourceforge.net/packages/regex.htm * Bison for Windows (bison.exe,依賴於Regex和Libintl) http://gnuwin32.sourceforge.net/packages/bison.htm * The AWK Programming Language (awk.exe) http://cm.bell-labs.com/cm/cs/awkbook/index.html -------------------- b. 二進制可以在下面的鏈接中找到,不需要自己編譯: * ed.exe和regex2.dll在gowin-env中。 https://bitbucket.org/akavel/gowin-env/downloads 或者在GnuWin32中安裝。 http://gnuwin32.sourceforge.net/packages.html -------------------- c. 注意事項: * 必須複製bison的二進制安裝包裏的share目錄(一些.m4文件) * 把msys/mingw自帶的awk去掉或重命名,使用awk.exe代替原有的awk文件 -------------------- d. 用到的工具合計有(不包括一些依賴庫的dll) gcc version 3.4.5 (mingw-vista special r3) GNU Make 3.81 GNU Ed 1.2 bison (GNU Bison) 2.4.1 awk version 20070501
  4. 解壓gomingw源碼包
  把gomingw的下載包解壓到/home/Administrator目錄下 目錄名爲/home/Administrator/go 刪除/home/Administrator/go/bin下的所有.exe文件。 只保留quietgcc文件。 刪除/home/Administrator/go/lib下的所有.a文件。 刪除/home/Administrator/go/pkg/windows_386下的所有庫文件。
  5. 編譯gomingw公共庫
  包括三個.a文件: lib9.a libbio.a libmach.a 執行命令如下: $ cd $ cd go/src/lib9/ $ make 出現錯誤: ../Make.inc:18: *** $GOROOT is not set; use gomake or set $GOROOT in your environment. Stop. 設置環境變量PATH和GOROOT(注意MinGW的環境變量區分大小寫): $ export GOROOT=/home/Administrator/go $ export PATH=/home/Administrator/go/bin:$PATH $ make 注意make可以重複使用,自動跳過之前已經完成的目標。 完成後,生成lib9.a 用類似的辦法編譯libbio.a和libmach.a $ cd ../libbio $ make $ cd ../libmach $ make 然後把生成的 lib9.a libbio.a libmach.a 複製到/home/Administrator/go/lib下
  6. 編譯gomingw編譯器工具、庫和runtime庫
  關於8g以及其它exe的作用和使用方法見這裏 http://golang-china.googlecode.com/svn/trunk/Chine se/golang.org/index.html http://code.google.com/p/golang-china/ 和x86相關的重要可執行文件和庫有 * gc.a * 8g.exe * 8l.exe(依賴於gc.a) 另外,由於runtime.a這個go庫一般都會使用到, 所以還需要以下工具的幫助。 * cc.a * 8c.exe(依賴於cc.a) * gopack.exe * 8a.exe * runtime.a(依賴於cc.a,8a.exe和gopack.exe) 執行以下命令:(同樣需要設置GOROOT和PATH,同上) $ cd $ cd go/src/cmd/gc $ make (如果失敗,請檢查awk.exe是否存在,原有awk是否重命名, 然後用make clean all重新編譯) $ cd ../8g $ make $ cd ../8l $ make $ cd ../cc $ make $ cd ../8c $ make $ cd ../gopack $ make $ cd ../8a $ make 然後把編譯好的8g.exe, 8l.exe, 8c.exe, 8a.exe, gopack.exe
  全部複製到/home/Administrator/go/bin下,繼續下面的runtime.a編譯 $ cd ../../pkg/runtime/ $ make 輸出文件runtime.a在_obj目錄下,複製到 /home/Administrator/go/pkg/windows_386目錄下 (此時目錄中只有一個.a文件)
  7. 最簡單的測試
  測試最簡單的go程序 $ cd $ cd go/test $ 8g -h gc: usage: 8g [flags] file.go... flags: -I DIR search for packages in DIR -d print declarations -e no limit on number of errors printed -f print stack frame structure -h panic on an error -o file specify output file -S print the assembly language -V print the compiler version -u disable package unsafe -w print the parse tree after typing -x print lex tokens $ 8g helloworld.go $ ls helloworld.* helloworld.8 helloworld.go $ 8l -h usage: 8l [-options] [-E entry] [-H head] [-I interpreter] [-L dir] [-T text] [-R rnd] [-r path] [-o out] main.8 $ 8l helloworld.8 $ ls *.exe 8.out.exe $ ./8.out.exe hello, world 注意,這裏使用8g和8l可以正確地找到庫(因爲前面編譯的時候已經設置好), 但實際操作(脫離MinGW環境)需要重新設置環境變量指向新的路徑,見 http://code.google.com/p/golang-china/wiki/Install 生成的8.out.exe是原生的Windows可執行程序,僅導入KERNEL32.DLL, 所以可以獨立於MinGW和Go的環境運行。
  8. 一些問題
  * 如果make沒有響應,直接結束進程然後重新運行make。
  (待補充)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章