简体   繁体   中英

Company-clang mode in emacs on windows

I'm having trouble with the last step in getting clang to work with company-mode on emacs.

I have

(setenv "PATH" (concat (getenv "PATH") ";C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\amd64;C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\amd64\\amd64;"))
(custom-set-variables
'(company-c-headers-path-system
   (quote
    ("c:/users/chowron/Documents/Development/include" "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\include" "C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\shared" "C:\\Program Files (x86)\\Windows Kits\\8.1\\Include\\um")))
 '(company-clang-arguments
   (quote
    ("-I \"C:\\\\Program Files (x86)\\\\Microsoft Visual Studio 14.0\\\\VC\\\\include\"" "-I \"c:\\\\Program Files (x86)\\\\Windows Kits\\\\10\\\\Include\\\\10.0.10586.0\\\\ucrt\"" "-I \"c:\\\\users\\\\chowron\\\\Documents\\\\Development\\\\include\"")))
 '(company-clang-executable
   "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\ClangC2\\bin\\amd64\\clang.exe")
 '(company-clang-insert-arguments nil))

In a simple program like

#include <iostream>
#include <string>
int main(int argc, char** argv) {
  std::string food;
  food. // Completion at point here
}

I see in clang-error

clang failed with error 1:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ClangC2\bin\amd64\clang.exe -fsyntax-only -Xclang -code-completion-macros -x c++ -I "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\include" -I "c:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.10586.0\\ucrt" -I "c:\\users\\chowron\\Documents\\Development\\include" -Xclang -code-completion-at=-:9:8 -

<stdin>:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^
1 error generated.

Running this on CMD.exe, however seems to work fine. Using stdin to input the file with a CTRL-Z at the end gives a bunch of warnings and eventually

...
COMPLETION: pop_back : [#void#]pop_back()
COMPLETION: push_back : [#void#]push_back(<#char _Ch#>)
COMPLETION: rbegin : [#reverse_iterator#]rbegin()
COMPLETION: rbegin : [#const_reverse_iterator#]rbegin()[# const#]
...

So I think I have the command line args and paths set up ok within emacs, but there is some setting or emacs function missing?

I found that the issue was in how the include "-I" paths were set. For anyone who might encounter the same problem.

In the .emacs setup, you have to write it like

(quote
    ("-IC:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\include" "-Ic:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.10586.0\\ucrt" "-Ic:\\users\\chowron\\Documents\\Development\\include" "-v")))

There are no quotes around the 'Program Files (x86)...' paths. Let clang do the interpretation.

As an extra note, this works with the clang bundled with VS2015 Release 2 and upwards at least. It should work with official releases too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM