使用MinGW 編譯 iconv 庫


原文鏈接: http://www.code-by.org/viewtopic.php?f=54&t=166

GNU頁面
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

已有的環境:msys2.0, mingw, GnuWin32工具集

解壓后先別急着configure
先看看 README.woe32

Building requires the mingw or cygwin development environment (includes gcc).
I recommend to use the cygwin environment as the development environment
and mingw only as the target (runtime, deployment) environment.
For this, you need to install

  • cygwin,
  • the mingw runtime package, also from the cygwin site.

首先安裝cygwin,
進入目錄后執行 ./configure , 第一個問題

checking if gcc supports -fno-rtti -fno-exceptions... ./configure: line 7594: diff:
command not found

缺個diff.exe,用everything 搜索到 C:\Program Files (x86)\GnuWin32\bin 下面有一個,復制到 C:\cygwin64\bin,
先不急着執行./configure,單獨執行diff.exe 提示缺少 libintl3.dll,將這個文件也復制過來,
再次執行diff.exe 提示缺少 libiconv2.dll,再復制,沒問題了。
(如果你從別的地方獲取diff,可能不需要依賴dll,也可能依賴別的庫,用類似的方法配置齊全就是了)

執行 ./configure 沒有出現明顯問題

執行 make ,提示

./relocatable.c: In function 'libcharset_relocate':
:0:12: error: expected expression before '/' token
./relocatable.c:423:37: note: in expansion of macro 'INSTALLDIR'
const char *orig_installdir = INSTALLDIR;
^~~~~~~~~~
make[2]: *** [Makefile:65: relocatable.lo] Error 1
make[2]: Leaving directory 'C:/Users/ViANG/Desktop/libiconv-1.14/libcharset/lib'
make[1]: *** [Makefile:34: all] Error 2
make[1]: Leaving directory 'C:/Users/ViANG/Desktop/libiconv-1.14/libcharset'
make: *** [Makefile:42: lib/localcharset.h] Error 2

好像是說這個 INSTALLDIR 的宏里面,包含了不可預料的表達式(在/之前),但是我也不知道怎么看INSTALLDIR的值,
用grep -R "INSTALLDIR" * 看了一下

build-aux/install-reloc: -D"INSTALLPREFIX="$prefix"" -D"INSTALLDIR
="$installdir""
lib/Makefile:-DENABLE_RELOCATABLE=1 -DIN_LIBRARY -DINSTALLDIR="$(libdir)" -DNO
_XMALLOC
lib/Makefile.in:-DENABLE_RELOCATABLE=1 -DIN_LIBRARY -DINSTALLDIR="$(libdir)" -
DNO_XMALLOC \

大概是從某個參數中傳遞進去的,既然它的內容有毒,而且只有一處,那自己改寫試試:
找到:libiconv-1.14\libcharset\lib\relocatable.c


const char *orig_installdir = INSTALLDIR;
改為
const char *orig_installdir = "/usr/local/cygwin";

同時 mkdir /usr/local/cygwin
然后執行
$ ./configure --prefix=/usr/local/cygwin
$ make
提示錯誤

C:\MinGW\bin\ranlib.exe: '/cygdrive/c/Users/name/Desktop/libiconv-1.14/lib/libcharset.a':
No such file

試了一下,對於mingw和msys的那一套,可以接受的路徑是 /c/usr/...這樣的,而在cygwin中的路徑是 /cygdrive/c/usr...
試着用sed和grep 批量替換,以及尋找 生成路徑的 cygpath命令,修改相應的參數,但還是失敗了。

分割線

既然Cygwin 路徑和 Msys mingw不兼容,而我對這一系列的東西不太熟,只能再換MSYS試試了
按cygwin的方法把diff.exe和相關的文件復制到 c:/mingw/bin

打開 MSYS2 Shell

$ ./configure
configure: error: cannot guess build type; you must specify one

添加參數:

$ ./configure --build=mingw32

看上去沒什么問題

$ make

跑了一大段后,出現前面同樣的問題:

./relocatable.c: In function 'libiconv_relocate':
:0:12: error: 'C' undeclared (first use in this function)
./relocatable.c:423:37: note: in expansion of macro 'INSTALLDIR'
const char *orig_installdir = INSTALLDIR;
^~~~~~~~~~
:0:12: note: each undeclared identifier is reported only once for
each function it appears in./relocatable.c:423:37: note: in expansion of macro 'INSTALLDIR'
const char *orig_installdir = INSTALLDIR;
^~~~~~~~~~
:0:13: error: expected ',' or ';' before ':' token
./relocatable.c:423:37: note: in expansion of macro 'INSTALLDIR'
const char *orig_installdir = INSTALLDIR;
^~~~~~~~~~
make[1]: *** [Makefile:87: relocatable.lo] Error 1
make[1]: Leaving directory 'C:/Users/ViANG/Desktop/libiconv-1.14/lib'
make: *** [Makefile:33: all] Error 2

找到 libiconv-1.14/lib/relocatable.c
改 INSTALLDIR 為 "/usr/local/cygwin" (忘了去mkdir,好像也沒什么問題),繼續

$ make
$ make install

看上去沒什么問題了 :coverface1


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM