我正在尝试安装 Ruby gem github-linguist。我在 Windows 机器上,尝试通过 Msys2、Mingw64 和常规 Windows 命令 shell 执行
gem install github-linguist
。我每次都得到相同的输出:
Building native extensions. This could take a while...
ERROR: Error installing github-linguist:
ERROR: Failed to build gem native extension.
current directory: C:/ghcup/msys64/mingw64/lib/ruby/gems/3.3.0/gems/charlock_holmes-0.7.9/ext/charlock_holmes
C:/ghcup/msys64/mingw64/bin/ruby.exe extconf.rb
checking for pkg-config for icu-i18n... not found
checking for pkg-config for icu-io... not found
checking for pkg-config for icu-uc... not found
checking for -licui18n... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include=${opt-dir}/include
--without-opt-include
--with-opt-lib=${opt-dir}/lib
--without-opt-lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/ghcup/msys64/mingw64/bin/$(RUBY_BASE_NAME)
--with-icu-dir
--without-icu-dir
--with-icu-include=${icu-dir}/include
--without-icu-include
--with-icu-lib=${icu-dir}/lib
--without-icu-lib
--with-icu-i18n-dir
--without-icu-i18n-dir
--with-icu-i18n-include=${icu-i18n-dir}/include
--without-icu-i18n-include
--with-icu-i18n-lib=${icu-i18n-dir}/lib
--without-icu-i18n-lib
--with-icu-i18n-config
--without-icu-i18n-config
--with-pkg-config
--without-pkg-config
--with-icu-io-dir
--without-icu-io-dir
--with-icu-io-include=${icu-io-dir}/include
--without-icu-io-include
--with-icu-io-lib=${icu-io-dir}/lib
--without-icu-io-lib
--with-icu-io-config
--without-icu-io-config
--with-icu-uc-dir
--without-icu-uc-dir
--with-icu-uc-include=${icu-uc-dir}/include
--without-icu-uc-include
--with-icu-uc-lib=${icu-uc-dir}/lib
--without-icu-uc-lib
--with-icu-uc-config
--without-icu-uc-config
--with-icui18n-dir
--without-icui18n-dir
--with-icui18n-include=${icui18n-dir}/include
--without-icui18n-include
--with-icui18n-lib=${icui18n-dir}/lib
--without-icui18n-lib
--with-icui18nlib
--without-icui18nlib
C:/ghcup/msys64/mingw64/lib/ruby/3.3.0/mkmf.rb:480:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from C:/ghcup/msys64/mingw64/lib/ruby/3.3.0/mkmf.rb:573:in `try_link0'
from C:/ghcup/msys64/mingw64/lib/ruby/3.3.0/mkmf.rb:591:in `try_link'
from C:/ghcup/msys64/mingw64/lib/ruby/3.3.0/mkmf.rb:809:in `try_func'
from C:/ghcup/msys64/mingw64/lib/ruby/3.3.0/mkmf.rb:1056:in `block in have_library'
from C:/ghcup/msys64/mingw64/lib/ruby/3.3.0/mkmf.rb:983:in `block in checking_for'
from C:/ghcup/msys64/mingw64/lib/ruby/3.3.0/mkmf.rb:344:in `block (2 levels) in postpone'
from C:/ghcup/msys64/mingw64/lib/ruby/3.3.0/mkmf.rb:314:in `open'
from C:/ghcup/msys64/mingw64/lib/ruby/3.3.0/mkmf.rb:344:in `block in postpone'
from C:/ghcup/msys64/mingw64/lib/ruby/3.3.0/mkmf.rb:314:in `open'
from C:/ghcup/msys64/mingw64/lib/ruby/3.3.0/mkmf.rb:340:in `postpone'
from C:/ghcup/msys64/mingw64/lib/ruby/3.3.0/mkmf.rb:982:in `checking_for'
from C:/ghcup/msys64/mingw64/lib/ruby/3.3.0/mkmf.rb:1051:in `have_library'
from extconf.rb:37:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
C:/ghcup/msys64/mingw64/lib/ruby/gems/3.3.0/extensions/x64-mingw32/3.3.0/charlock_holmes-0.7.9/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in C:/ghcup/msys64/mingw64/lib/ruby/gems/3.3.0/gems/charlock_holmes-0.7.9 for inspection.
Results logged to C:/ghcup/msys64/mingw64/lib/ruby/gems/3.3.0/extensions/x64-mingw32/3.3.0/charlock_holmes-0.7.9/gem_make.ou
错误消息中提到的
mkmf.log
文件内容如下:
pkg_config: checking for pkg-config for icu-i18n... -------------------- not found
PATH=".;C:/ghcup/msys64/mingw64/lib;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\PuTTY\;C:\Program Files\nodejs\;C:\Elm\0.19.1\bin;C:\Users\dawie\AppData\Local\Microsoft\WindowsApps;C:\Users\dawie\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\dawie\AppData\Local\Programs\MiKTeX\miktex\bin\x64\;C:\Users\dawie\AppData\Local\Programs\R\R-4.4.1\bin\;C:\Users\dawie\AppData\Local\Programs\Git\cmd;C:\ghcup\bin;C:\Users\dawie\AppData\Roaming\npm;C:\ghcup\msys64\usr\bin;C:\ghcup\msys64\mingw64\bin;" pkg-config --exists icu-i18n
package configuration for icu-i18n is not found
--------------------
pkg_config: checking for pkg-config for icu-io... -------------------- not found
PATH=".;C:/ghcup/msys64/mingw64/lib;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\PuTTY\;C:\Program Files\nodejs\;C:\Elm\0.19.1\bin;C:\Users\dawie\AppData\Local\Microsoft\WindowsApps;C:\Users\dawie\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\dawie\AppData\Local\Programs\MiKTeX\miktex\bin\x64\;C:\Users\dawie\AppData\Local\Programs\R\R-4.4.1\bin\;C:\Users\dawie\AppData\Local\Programs\Git\cmd;C:\ghcup\bin;C:\Users\dawie\AppData\Roaming\npm;C:\ghcup\msys64\usr\bin;C:\ghcup\msys64\mingw64\bin;" pkg-config --exists icu-io
package configuration for icu-io is not found
--------------------
pkg_config: checking for pkg-config for icu-uc... -------------------- not found
PATH=".;C:/ghcup/msys64/mingw64/lib;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\PuTTY\;C:\Program Files\nodejs\;C:\Elm\0.19.1\bin;C:\Users\dawie\AppData\Local\Microsoft\WindowsApps;C:\Users\dawie\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\dawie\AppData\Local\Programs\MiKTeX\miktex\bin\x64\;C:\Users\dawie\AppData\Local\Programs\R\R-4.4.1\bin\;C:\Users\dawie\AppData\Local\Programs\Git\cmd;C:\ghcup\bin;C:\Users\dawie\AppData\Roaming\npm;C:\ghcup\msys64\usr\bin;C:\ghcup\msys64\mingw64\bin;" pkg-config --exists icu-uc
package configuration for icu-uc is not found
--------------------
PATH=".;C:/ghcup/msys64/mingw64/lib;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\PuTTY\;C:\Program Files\nodejs\;C:\Elm\0.19.1\bin;C:\Users\dawie\AppData\Local\Microsoft\WindowsApps;C:\Users\dawie\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\dawie\AppData\Local\Programs\MiKTeX\miktex\bin\x64\;C:\Users\dawie\AppData\Local\Programs\R\R-4.4.1\bin\;C:\Users\dawie\AppData\Local\Programs\Git\cmd;C:\ghcup\bin;C:\Users\dawie\AppData\Roaming\npm;C:\ghcup\msys64\usr\bin;C:\ghcup\msys64\mingw64\bin;" "gcc -o conftest.exe -IC:/ghcup/msys64/mingw64/include/ruby-3.3.0/x64-mingw32 -IC:/ghcup/msys64/mingw64/include/ruby-3.3.0/ruby/backward -IC:/ghcup/msys64/mingw64/include/ruby-3.3.0 -I. -D_WIN32_WINNT=0x0600 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wp,-D__USE_MINGW_ANSI_STDIO=1 -Wno-incompatible-pointer-types conftest.c -L. -LC:/ghcup/msys64/mingw64/lib -L. -fstack-protector-strong -Wl,--no-as-needed -lx64-msvcrt-ruby330 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi -lbcrypt "
In file included from C:/ghcup/msys64/mingw64/include/ruby-3.3.0/ruby/internal/config.h:22,
from C:/ghcup/msys64/mingw64/include/ruby-3.3.0/ruby/ruby.h:15,
from C:/ghcup/msys64/mingw64/include/ruby-3.3.0/ruby.h:38,
from conftest.c:1:
C:/ghcup/msys64/mingw64/include/ruby-3.3.0/x64-mingw32/ruby/config.h:217:15: error: two or more data types in declaration specifiers
217 | #define uid_t int
| ^~~
C:/ghcup/msys64/mingw64/include/ruby-3.3.0/x64-mingw32/ruby/config.h:218:15: error: two or more data types in declaration specifiers
218 | #define gid_t int
| ^~~
In file included from C:/ghcup/msys64/mingw64/include/ruby-3.3.0/ruby/internal/value.h:23,
from C:/ghcup/msys64/mingw64/include/ruby-3.3.0/ruby/internal/intern/class.h:24,
from C:/ghcup/msys64/mingw64/include/ruby-3.3.0/ruby/internal/anyargs.h:76,
from C:/ghcup/msys64/mingw64/include/ruby-3.3.0/ruby/ruby.h:27:
C:/ghcup/msys64/mingw64/include/ruby-3.3.0/ruby/internal/static_assert.h:51:46: error: static assertion failed: "sizeof_long: SIZEOF_LONG == sizeof(long)"
51 | # define RBIMPL_STATIC_ASSERT0 __extension__ _Static_assert
| ^~~~~~~~~~~~~~
C:/ghcup/msys64/mingw64/include/ruby-3.3.0/ruby/internal/static_assert.h:70:5: note: in expansion of macro ΓÇÿRBIMPL_STATIC_ASSERT0ΓÇÖ
70 | RBIMPL_STATIC_ASSERT0(expr, # name ": " # expr)
| ^~~~~~~~~~~~~~~~~~~~~
C:/ghcup/msys64/mingw64/include/ruby-3.3.0/ruby/internal/value.h:129:1: note: in expansion of macro ΓÇÿRBIMPL_STATIC_ASSERTΓÇÖ
129 | RBIMPL_STATIC_ASSERT(sizeof_long, SIZEOF_LONG == sizeof(long));
| ^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/w32api/winsock2.h:56,
from conftest.c:3:
/usr/include/w32api/psdk_inc/_fd_types.h:100:2: warning: #warning "fd_set and associated macros have been defined in sys/types. This can cause runtime problems with W32 sockets" [-Wcpp]
100 | #warning "fd_set and associated macros have been defined in sys/types. \
| ^~~~~~~
/usr/include/w32api/winsock2.h:1031:34: error: conflicting types for ΓÇÿselectΓÇÖ; have ΓÇÿint(int, fd_set *, fd_set *, fd_set *, const TIMEVAL *)ΓÇÖ
1031 | WINSOCK_API_LINKAGE int WSAAPI select(int nfds,fd_set *readfds,fd_set *writefds,fd_set *exceptfds,const TIMEVAL *timeout);
| ^~~~~~
In file included from /usr/include/sys/types.h:50,
from C:/ghcup/msys64/mingw64/include/ruby-3.3.0/ruby/defines.h:19,
from C:/ghcup/msys64/mingw64/include/ruby-3.3.0/ruby/ruby.h:25:
/usr/include/sys/select.h:80:5: note: previous declaration of ΓÇÿselectΓÇÖ with type ΓÇÿint(int, fd_set *, fd_set *, fd_set *, struct timeval *)ΓÇÖ
80 | int select __P ((int __n, fd_set *__readfds, fd_set *__writefds,
| ^~~~~~
/usr/include/w32api/winsock2.h:1040:34: error: conflicting types for ΓÇÿgethostnameΓÇÖ; have ΓÇÿint(char *, int)ΓÇÖ
1040 | WINSOCK_API_LINKAGE int WSAAPI gethostname(char *name,int namelen);
| ^~~~~~~~~~~
In file included from /usr/include/ssp/stdio.h:34,
from /usr/include/stdio.h:804,
from C:/ghcup/msys64/mingw64/include/ruby-3.3.0/ruby/defines.h:16:
/usr/include/ssp/unistd.h:60:1: note: previous definition of ΓÇÿgethostnameΓÇÖ with type ΓÇÿint(char *, size_t)ΓÇÖ {aka ΓÇÿint(char *, long unsigned int)ΓÇÖ}
60 | __ssp_redirect(int, gethostname, (char *__buf, size_t __len), \
| ^~~~~~~~~~~~~~
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <winsock2.h>
4: #include <windows.h>
5: int main(int argc, char **argv)
6: {
7: return !!argv[argc];
8: }
/* end */
问题似乎是
-licui18n
库的问题,因此我尝试在 Msys2 shell 中使用 pacman -S mingw-w64-x86_64-icu
安装该软件包,并且它运行完美,没有错误。但当我再次运行 gem install github-linguist
时,它仍然不起作用。我不确定错误消息“您必须首先安装开发工具”是什么意思,这不是很具体。
我对 Makefile 不太熟悉,所以对于有更多经验的人来说,错误消息可能更容易理解。
解决了!我需要将安装程序指向 icu lib 文件所在的位置。我在尝试解决问题的各种尝试中多次安装了该软件包,因此将
.dll
文件安装到 /mingw64/lib/
和 /usr/lib/
目录中。我在 Mingw64 shell 中运行了以下命令:find /usr -name 'libicu*'
,看到了这个:
/usr/lib/libicudata75.dll.a
/usr/lib/libicui18n.dll.a
/usr/lib/libicui18n75.dll.a
/usr/lib/libicuio.dll.a
/usr/lib/libicuio75.dll.a
/usr/lib/libicutest.dll.a
/usr/lib/libicutest75.dll.a
/usr/lib/libicutu.dll.a
/usr/lib/libicutu75.dll.a
/usr/lib/libicuuc.dll.a
/usr/lib/libicuuc75.dll.a
/usr/lib/w32api/libicu.a
注意
libicui18n.dll.a
文件的存在。这正是安装人员所需要的。然后我运行了gem install github-linguist -- --with-icu-lib=/usr/lib
,它成功了!