windows 下 使用 irony 时出错,代码 53

我在 github 的官网上已经提问了,因为 google 不到相关的答案,而且我觉得自己已经做到力不能及了,在这里也提问一下: 我使用的是 win7 64位旗舰版,msys2-x86_64 和 GNU Emacs 25.2.1 (x86_64-w64-mingw32), 用 pacman 安装了 mingw-w64-x86_64-clang 和 mingw-w64-x86_64-cmake, 然后我这样编译 irony-server:

cd server
mkdir build
cd build
cmake -DLIBCLANG_INCLUDE_PATH=llvm-config --includedir -DLIBCLANG_LIBRARY_PATH=llvm-config --libdir -D CMAKE_CXX_COMPILER=clang-c++.exe -D CMAKE_MAKE_PROGRAM=mingw32-make.exe -G "MSYS Makefiles" ..

编译成功,然后把 irony-server.exe 复制到 .emacs.d/irony/bin, 也一起复制 libstdc+±6.dll 到同一个目录下,然后把 mingw64/bin 加到 PATH 环境变量. 然后,我打开命令提示符,运行以下命令检查:

irony-server.exe --version

得到的结果是:

irony-server version 1.0.0 clang version 4.0.0 (tags/RELEASE_400/final)

这说明服务器本身没问题,然后是 emacs 的配置:

(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)

;; Windows performance tweaks
;;
(when (boundp 'w32-pipe-read-delay)
(setq w32-pipe-read-delay 0))
;; Set the buffer size to 64K on Windows (from the original 4K)
(when (boundp 'w32-pipe-buffer-size)
(setq irony-server-w32-pipe-buffer-size (* 64 1024)))

然后打开 hello.c ,运行 C-M-i ,但出错了:

irony–find-server-executable: Irony-Mode server error: “irony-server is broken! g:/slkshare/emacs/.emacs.d/irony/bin/irony-server.exe exited with status 53”

然后我以为是 emacs 中的路径没设好: 所以就执行 (getenv “PATH”) , 发现没有 mingw64/bin ,就加上:

(setenv "PATH" (concat
                "/d/dev/msys64/usr/bin" ":"
                "/d/dev/msys64/mingw64/bin" ":"
                (getenv "PATH")))

路径对了,但还是相同的错误,怎么办?

另外 ycmd 也是,编译需要 visual stdio ,我没装,而是到知乎上下载了预编译的,https://www.zhihu.com/question/25437050 的版本,然后也是用官网下载的 32位的 python2.7 来执行,启动后,ycmd 的服务器能正常运行一会儿,很快就显示 ycmd server killed 然后就不行了。 所以,两个主流的补全插件都不行,我还是用回 autocomplete 和 yasnippet 了。

建议用 VS 编译,mingw 编译出来的东西不能运行是很常见的。

嗯,好的,我只是好奇,为什么在命令提示符下能工作的,到 emacs 中就不能调用了。

irony正常使用是这样启动的: irony-server.exe -i

你运行irony-server.exe --version估计只执行了程序最前面的几行代码打印了一下版本号就退出了.

可以在命令行运行irony-server.exe -i试试

嗯,我的hello.c 是这样的:

\#include stdio.h
\#include stdlib.h

int main(void)
{
  printf("Hello World!\n");
  for
}

然后我想补全第7行的 for 所以我就 irony-server.exe -i 进入后用命令:

complete g:\\slkshare\\proj1\\src\\hello.c 7 3

得到结果是:

execute: Command{action=Command::Complete, file='g:\slkshare\proj1\src\hello.c',
 unsavedFile='', dir='', line=7, column=3, flags=[], opt=off}
(success . t)

;;EOT

尖括号打不出,不知该怎样贴代码。

windows上PATH里的分隔符好像不是冒号,好像是分号

就是冒号。你想多了。 错看成路径符了。

windows 下的 PATH 变量确实是分号,但 emacs 中 的还是按照 linux 风格的,用冒号吧。 我特地下载了 vs2017的 社区版,安装了官网下载的 cmake 和 llvm ,然后发现 llvm 安装时说找不到 msbuild 的 tools directory ,不能集成,然后在运行 cmake 时还出错, 做出来的 sln 用 vs2017 不能正确编译。

; 使用 msys 作为 shell
(provide 'set-myshell)

(setq my_msys_cmd (concat my_c_path "/MinGw/msys/1.0/bin/bash.exe"))
(setq my_old_cmd_path (getenv "PATH"))
(setq my_old_cmd  (concat (getenv "EMACS_DIR") "/bin/cmdproxy.exe"))
(global-set-key [C-f1] 'msys_bash)

(defun msys_bash ()
  "Toggle msys bash shell and windows cmd."
  (interactive)
  (if (string-equal explicit-shell-file-name my_old_cmd)
      (progn 
	(setq explicit-shell-file-name my_msys_cmd)
	(setq shell-file-name  "bash") 
	(setq ediff-shell   explicit-shell-file-name)    ; Ediff shell
	(setq explicit-shell-args       '("--noediting" "--login" "-i"))
	(setenv "SHELL" explicit-shell-file-name)
	(setenv "PATH" "/d/dev/msys64/usr/bin:/usr/sbin:/sbin:/usr/bin:.:/usr/local/bin:/mingw/bin:/bin:~/bin:/d/dev/UnxUtils/bin")
	)
    (progn
      (setq explicit-shell-file-name my_old_cmd)
      (setq shell-file-name  explicit-shell-file-name) 
      (setq ediff-shell     explicit-shell-file-name)    ; Ediff shell
      (setq explicit-shell-args       nil)
      (setenv "SHELL" explicit-shell-file-name)
      (setenv "PATH" my_old_cmd_path))
    ))

(msys_bash)
(msys_bash)

我知道原因了,以上这段是我以前从某个地方抄来,用来改变 emacs 的 shell 环境的,去掉这个启动配置就可以了。

hello,我也是想在windows下使用irony,但是一直编不成功irony server。 首先我从irony的wiki里提供链接下载了msys2-x86_64-20170918.exe 然后使用pacman安装了mingw-w64-x86_64-clang和mingw-w64-x86_64-cmake。然后我执行了跟楼主一样的cmake命令,但是编译失败:

明显是因为 Cmake 找不到编译器

cmake -DLIBCLANG_LIBRARY=/mingw64/bin/clang.dll -G “MinGW Makefiles” … 没有指定compiler,默认用的g++,最后generate并编译成功了

在windows下编译irony-server.exe 总失败,我用的是visual studio , 说是找不到clang-c/Index.h …我在想:能不能把别人编译好的irony-server.exe拿来用?自己编译实在搞不定 我编译的输出结果是(我已经加粗了提示失败的地方):

c:\Users\cliyh\AppData\Roaming.emacs.d\elpa\irony-20180104.1109\server\build>cmake -DLIBCLANG_LIBRARY=c:\tools\LLVM\lib\libclang.lib -DLIBCLANG_INCLUDE_DIR=c:\tools\LLVM\lib -G “Visual Studio 14 2015 Win64” … – Selecting Windows SDK version to target Windows 10.0.16299. – The C compiler identification is MSVC 19.0.24210.0 – The CXX compiler identification is MSVC 19.0.24210.0 – Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe – Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe – works – Detecting C compiler ABI info – Detecting C compiler ABI info - done – Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe – Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe – works – Detecting CXX compiler ABI info – Detecting CXX compiler ABI info - done – Detecting CXX compile features – Detecting CXX compile features - done – Found LibClang: C:/tools/LLVM/lib/libclang.lib – Detecting Clang resource directory – Detecting Clang resource directory – fail CMake Warning at cmake/CheckClangResourceDir.cmake:77 (message): CheckClangResourceDir: failed to compile checker, please report.

Compile output: Change Dir: C:/Users/cliyh/AppData/Roaming/.emacs.d/elpa/irony-20180104.1109/server/build/CMakeFiles/CMakeTmp

Run Build Command:“C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe” “cmTC_e8b70.vcxproj” “/p:Configuration=Debug” “/p:VisualStudioVersion=14.0”

Microsoft ® Build Engine version 14.0.25420.1

Copyright © Microsoft Corporation. All rights reserved.

Build started 1/25/2018 12:00:28 AM.

Project “C:\Users\cliyh\AppData\Roaming.emacs.d\elpa\irony-20180104.1109\server\build\CMakeFiles\CMakeTmp\cmTC_e8b70.vcxproj” on node 1 (default targets).

PrepareForBuild:

Creating directory “cmTC_e8b70.dir\Debug”. Creating directory “C:\Users\cliyh\AppData\Roaming.emacs.d\elpa\irony-20180104.1109\server\build\CMakeFiles\CMakeTmp\Debug”. Creating directory “cmTC_e8b70.dir\Debug\cmTC_e8b70.tlog”.

InitializeBuildStatus:

Creating “cmTC_e8b70.dir\Debug\cmTC_e8b70.tlog\unsuccessfulbuild” because “AlwaysCreate” was specified.

ClCompile:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\CL.exe /c /IC:\tools\LLVM\lib /Zi /W3 /WX- /Od /Ob0 /D WIN32 /D _WINDOWS /D _HAS_EXCEPTIONS=0 /D “CMAKE_INTDIR=“Debug”” /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"cmTC_e8b70.dir\Debug" /Fd"cmTC_e8b70.dir\Debug\vc140.pdb" /Gd /TP /errorReport:queue /EHs-c- “C:\Users\cliyh\AppData\Roaming.emacs.d\elpa\irony-20180104.1109\server\build\CMakeFiles\CMakeTmp\LibClangDiagnosticsChecker.cpp” Microsoft ® C/C++ Optimizing Compiler Version 19.00.24210 for x64 Copyright © Microsoft Corporation. All rights reserved.

LibClangDiagnosticsChecker.cpp cl /c /IC:\tools\LLVM\lib /Zi /W3 /WX- /Od /Ob0 /D WIN32 /D _WINDOWS /D _HAS_EXCEPTIONS=0 /D “CMAKE_INTDIR=“Debug”” /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"cmTC_e8b70.dir\Debug" /Fd"cmTC_e8b70.dir\Debug\vc140.pdb" /Gd /TP /errorReport:queue /EHs-c- “C:\Users\cliyh\AppData\Roaming.emacs.d\elpa\irony-20180104.1109\server\build\CMakeFiles\CMakeTmp\LibClangDiagnosticsChecker.cpp”

cl : Command line warning D9025: overriding ‘/EHs’ with ‘/EHs-’ [C:\Users\cliyh\AppData\Roaming.emacs.d\elpa\irony-20180104.1109\server\build\CMakeFiles\CMakeTmp\cmTC_e8b70.vcxproj]

cl : Command line warning D9025: overriding ‘/EHc’ with ‘/EHc-’ [C:\Users\cliyh\AppData\Roaming.emacs.d\elpa\irony-20180104.1109\server\build\CMakeFiles\CMakeTmp\cmTC_e8b70.vcxproj]

C:\Users\cliyh\AppData\Roaming.emacs.d\elpa\irony-20180104.1109\server\build\CMakeFiles\CMakeTmp\LibClangDiagnosticsChecker.cpp(9): fatal error C1083: Cannot open include file: ‘clang-c/Index.h’: No such file or directory [C:\Users\cliyh\AppData\Roaming.emacs.d\elpa\irony-20180104.1109\server\build\CMakeFiles\CMakeTmp\cmTC_e8b70.vcxproj]

Done Building Project “C:\Users\cliyh\AppData\Roaming.emacs.d\elpa\irony-20180104.1109\server\build\CMakeFiles\CMakeTmp\cmTC_e8b70.vcxproj” (default targets) – FAILED.

Build FAILED.

“C:\Users\cliyh\AppData\Roaming.emacs.d\elpa\irony-20180104.1109\server\build\CMakeFiles\CMakeTmp\cmTC_e8b70.vcxproj” (default target) (1) ->

(ClCompile target) ->

cl : Command line warning D9025: overriding ‘/EHs’ with ‘/EHs-’ [C:\Users\cliyh\AppData\Roaming.emacs.d\elpa\irony-20180104.1109\server\build\CMakeFiles\CMakeTmp\cmTC_e8b70.vcxproj] cl : Command line warning D9025: overriding ‘/EHc’ with ‘/EHc-’ [C:\Users\cliyh\AppData\Roaming.emacs.d\elpa\irony-20180104.1109\server\build\CMakeFiles\CMakeTmp\cmTC_e8b70.vcxproj]

“C:\Users\cliyh\AppData\Roaming.emacs.d\elpa\irony-20180104.1109\server\build\CMakeFiles\CMakeTmp\cmTC_e8b70.vcxproj” (default target) (1) ->

(ClCompile target) ->

C:\Users\cliyh\AppData\Roaming.emacs.d\elpa\irony-20180104.1109\server\build\CMakeFiles\CMakeTmp\LibClangDiagnosticsChecker.cpp(9): fatal error C1083: Cannot open include file: ‘clang-c/Index.h’: No such file or directory [C:\Users\cliyh\AppData\Roaming.emacs.d\elpa\irony-20180104.1109\server\build\CMakeFiles\CMakeTmp\cmTC_e8b70.vcxproj]

2 Warning(s) 1 Error(s)

Time Elapsed 00:00:00.85

Call Stack (most recent call first): src/CMakeLists.txt:8 (check_clang_resource_dir)

– Irony package version is ‘1.2.0’ – Found emacs: C:/Emacs64/bin/emacs.exe – Configuring done – Generating done – Build files have been written to: C:/Users/cliyh/AppData/Roaming/.emacs.d/elpa/irony-20180104.1109/server/build