c++vimclangyoucompletemeclang-cl

Why YouCompleteMe does not work after dot?


I have installed YouCompleteMe according to the installation guide. I'm using gVim on Windows machine. Basic symbolic completion is working but I cannot make it to autocomplete from my headers.

If I have:

#include <vector>
using namespace std;
vector<int> myVector;

then it will be no completion found for myVector.<smth like push_back etc...>

Vim status bar says:

--User defined completion (^U^N^P) Pattern not found

or

--Omni completion (^O^N^P) Pattern not found

Diagnostics

I started to diagnose the problem. :YcmDiags command gives a list of errors coming from header files. As YouCompleteMe uses clang to constantly compile sources I tried to compile my file with clang. I also know that I should specify command line options for clang in flags in .ycm_extra_conf.py. I don't know whether YCM runs clang.exe or clang-cl.exe but I actually successfully compiled my .cpp file using clang-cl.exe manually after running vsvars32.bat from command line. I didn't succeeded to compile using clang.exe.

Here is my .ycm_extra_conf.py file flags section:

flags = [ 
'-std=c++11',
'-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.10150.0/ucrt',
'-I', 'C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/atlmfc/include',
'-I', 'C:/Program Files (x86)/Windows Kits/NETFXSDK/4.6/include/um',
'-I', 'C:/Program Files (x86)/Windows Kits/8.1/Include/um',
'-I', 'C:/Program Files (x86)/Windows Kits/8.1/Include/shared',
'-I', 'C:/Program Files (x86)/Windows Kits/8.1/Include/winrt',
'/link', '/LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\lib" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\lib\10.0.10150.0\ucrt\x86" /LIBPATH:"C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x86"',
'/EHsc']

Solution

  • micbou gave me an answer to this question.

    On Windows, Clang uses i686-pc-windows-gnu on 32-bit and x86_64-w64-windows-gnu on 64-bit as its default target. You need to change it to MSVC by adding the following flag:

    flags = [ '--target=<arch>-pc-windows-msvc<xx.yy.zzzzz>' ] where is i686 on 32-bit, x86_64 on 64-bit and <xx.yy.zzzzz> is the version of MSVC. You can found it by running the VC++ compiler cl.exe. In your case, since you are using MSVC 14 on 32-bit, the target should be i686-pc-windows-msvc19.00.23506.

    With the include flags you already added, you should get completions from the headers.

    In my particular case --target=x86_64-pc-windows-msvc19.00.23026 flag resolved the issue.