spacemacs 中有哪些比较好的 C/C++ 配置

最近在写C, 找了一下 emacs 的配置,发现这个很好: C/C++ Development Environment for Emacs
可这个是针对C/C++单独配置的,我用 spacemacs, 所以想问一下,spacemacs 有没有什么相关的。

spacemacs 的 c-c++ layer, 想功能多一些就还要再装上好几个别的 layer(semantic,cscope, auto-completion,ycmd),感觉好庞大啊!

2 个赞

我也是在写C/C++程序,共同学习一下spacemacs吧.

1 个赞

好的啊!

用过 function-args 吗?

我照着第一个链接,给spacemacs配置了几个package,已经很好用了!

C/C++ Development Environment for Emacs 是几年前的老帖了,要整合进 spacemacs 似乎不太容易,而且它竟然把 CEDET 又捡起来了。

spacemacs 的 c-c++ layer 没用过,只知道 ycmd 安装比较麻烦

现在很少写 c,偶尔用下 irony-mode 还可以。irony 跟 ycmd 是一个级别的东西,整合进 spacemacs 应该简单替换就可以了,其他如 company 之类的沿用。

论坛之前有不少关于 c/c++ 配置的讨论:'ycmd irony c++' 的搜索结果 - Emacs China

另外,陈斌大神的 https://github.com/redguardtoo/cpputils-cmake 也是一个相当完整的 c/c++ 配置。

1 个赞

这是一份新的 c-ide 配置,在 tuhdo 的配置上做了比较多的修改:

http://syamajala.github.io/c-ide.html

Emacs as C++ IDE

This guide is meant as supplement to Tudho’s C/C++ Development Enivornment for Emacs Guide. It assumes you:

  • Use CMake to build your projects
  • Have Clang/LLVM installed
  • Want to setup RTags and Irony
  • Want to integrate RTags and Irony with Company.
1 个赞

我都配置,(不是spacemacs,原生的),是参照一下两个取舍而得: http://tuhdo.github.io/c-ide.html http://syamajala.github.io/c-ide.html

基本的一些source nagivation和基本editing功能来源于第一个老贴,虽然老但它写的很清楚。我选择:基本的editing推荐+ helm-gtags,以及一些小插件,比如function-args什么的(基本弃用CEDET,只用它的semantic-mode, 用于辅助function-args 或者 helm-semantic-or-imenusticky-function什么的)

重量级的补全用irony-mode, 精确的C++语言的tag跳转用rtags. (helm-gtags我也开着,它支持别的语言,用makefile的话我图简单粗暴一般就用gtags了。如果用cmake且工程大了点,复杂C++特性用的多就主要用rtags了)。 Flycheck整合使用irony。

别的也没什么了

看我的dotfiles:https://github.com/oracleyue/dotfiles/tree/master/_emacs.d.25.1.osx/init 我陆陆续续陪了四套: auto-complete-clang-asynccompany-clang; irony-mode; irony-mode + rtags + cmake-ide,(默认helm-gtags总是开着的),分别对应于

  • emacs-init-cc-ac.el
  • emacs-init-cc-comp.el
  • emacs-init-irony.org
  • emacs-init-modern.org

我默认开的是第三个。不过我同时跑几个emacs servers (–daemon),所以转用第四上rtags也很方便;前两个弃用了。

1 个赞

在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

提示失败的地方,我已经加粗了

你看看这个帖子有没有帮助,它github给的wiki。我用的mac,不太清楚win。应该是缺少clang的头文件库,默认安装clang是没有这个的。不过当时我直接用homebrew安装再编译也不行,后来下载了源码,测试编译通过 而且能用,然后才又回头调用homebrew安装的库成功的;主要貌似是自动搜索头文件的位置失败,需要cmake时指定。我在我自己的那篇blog提供了我编译时的命令,你结合的改改试试?

另外,你应该用cmake编译吧?除非你设置visual studio是用cmake的;具体不懂啊,我只用过VC6.0啊,还是当年本科时学C++时 :slight_smile:

可以试试装个cygwin,我偶尔在windows下编译过东西,cygwin带的包基本能满足要求。

非常感谢,我去试试看

我是按照你给出的那个链接中使用visual studio编译的,用到了cmake

我之前用过cygwin,也用过cgywin里的emacs,后来是因为它自带的emacs版本太低了。不知道cygwin里的emacs对clang的支持如何,我回头试一下。

在windows下就是折腾,但是又不得不用。。。衰。。。

折腾了很久,最后发现Clion加emacs插件是最理想的c++ ide

不不,不是让你用cygwin的emacs,是,你要编译东西(比如irony-server.exe)的话,cygwin里基本都有一包包的头文件啥的,不用他就要到各处去找。

spacemacs c-c++ layer 髒東西太多了

不知道有什麼辦法讓 +tools/lsp 快點被作者接收 https://github.com/syl20bnr/spacemacs/pull/10211 … 之後應該會有鋪天蓋地的LSP包

C/C++ 推薦 lsp-mode + lsp-ui + cquery ,原因是 irony-mode 作者 Sarcasm 也說好用ycmd開發者跑來捧場

1 个赞

你好,我最近在研究这份配置。 但是不是里面有些代码错误。

一年前的配置,出错太正常了。

配置是有时效性的,现在建议使用 lsp-mode + ccls/cquery。