Sublime Forum

Clang (C/C++/Objective-C/Objective-C++) autocomplete

#121

Filed as issue 205

0 Likes

#122

With:

int main(int argc, char const* argv]) { int aaaaa = 0; int aaaaa = 0 return 0; }
select both aaaaa’s (with ctrl+d) and press space. Weird things happen. I’m reporting this here as project is closed for issues. I guess I will probably try to fix it myself eventually but there is probably steep learning curve when it comes to the plugin’s code.

0 Likes

#123

I’m new to sublime, and trying to configure SublimeClang package. I’ve wrote opengl c++ program and made it work by compiling manually in console with a single line (using mingw-g++), but clang fails with alot of an odd errors in VS headers, which I didn’t even included anywhere.
Here’s list of all my includes in my working code:

#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/freeglut.h>

Here’s my user-settings for SublimeClang package:

[code] {
// I was trying to remove clang’s default headers to fix this
“dont_prepend_clang_includes”: true,

// I was trying to make it analyze in different way, but not sure if that's correct. Anyway it didn't made any visible difference
//"analyzer_commandline":
//
//	 "g++",
//	 "-S",
//	 "-" // and what does this means?
//],

"options": "-IC:\\MinGW\\include\\"],
"debug_options": true

}
[/code]

Here’s the clang’s output I keep getting:

:0,0 - Fatal - too many errors emitted, stopping now [Disable with -ferror-limit=0]
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cmath:37,13 - Error - no member named 'abs' in the global namespace
C:/MinGW/include\stdio.h:154,21 - Error - definition of variable with array type needs an explicit size or an initializer
C:/MinGW/include\stdlib.h:196,22 - Error - definition of variable with array type needs an explicit size or an initializer
C:/MinGW/include\wctype.h:99,33 - Error - definition of variable with array type needs an explicit size or an initializer
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cwchar:25,52 - Error - no member named 'fgetws' in the global namespace
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cwchar:26,13 - Error - no member named 'fputws' in the global namespace
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cwchar:27,34 - Error - no member named 'getwc' in the global namespace
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cwchar:27,53 - Error - no member named 'getwchar' in the global namespace
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cwchar:29,34 - Error - no member named 'putwc' in the global namespace
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cwchar:29,53 - Error - no member named 'putwchar' in the global namespace
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\iosfwd:310,3 - Error - no member named 'wmemcpy_s' in the global namespace
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\iosfwd:407,3 - Error - no member named 'wmemcpy_s' in the global namespace
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\iosfwd:504,3 - Error - no member named 'memcpy_s' in the global namespace
C:/MinGW/include\ctype.h:112,33 - Error - redefinition of '_ctype'
C:/MinGW/include\ctype.h:112,33 - Error - definition of variable with array type needs an explicit size or an initializer
C:/MinGW/include\ctype.h:117,34 - Error - redefinition of '_pctype_dll'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\system_error:23,33 - Error - use of undeclared identifier 'EAFNOSUPPORT'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\system_error:24,19 - Error - use of undeclared identifier 'EADDRINUSE'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\system_error:25,26 - Error - use of undeclared identifier 'EADDRNOTAVAIL'
:0,0 - Fatal - too many errors emitted, stopping now [Disable with -ferror-limit=0]

So why it keep try including that headers? Where it even found their location anyway? It isn’t written in %path% or anywhere in sublime settings…

Sorry if this thread isn’t the right place to ask this question, just idk where it is.

0 Likes

#124

Clang will try (and usually succeed) to find the MS SDK if you have it installed. It won’t work properly with it but that doesn’t mean you have to prevent it from finding it. Just make sure that you specify MinGW includes so that these are found first.

For example I have these clang options specified which give quite good results*:

"-Wall", "-Werror", "-Wextra", "-Wnewline-eof", "-Wendif-labels", "-Wno-unused-parameter", "-Wno-missing-field-initializers", "-Wno-char-subscripts", "-Wno-unused-function", "-Wno-unnamed-type-template-args", "-Wno-c++11-extensions", "-Wno-covered-switch-default", "-Wno-unknown-pragmas", "-Wno-microsoft", "-O0", "-g", "-gdwarf-2", "-ferror-limit=0", "-fmsc-version=1600", "-fno-rtti", "-fno-exceptions", "-fvisibility-inlines-hidden", "-fno-threadsafe-statics", "-fcolor-diagnostics", "-fno-strict-aliasing", "-fstack-protector-all", "-fsyntax-only", "-std=c++11", "-fgnu-runtime", "-m32", "-IC:/MinGW/lib/gcc/mingw32/4.7.2/include", "-IC:/MinGW/lib/gcc/mingw32/4.7.2/include/c++", "-IC:/MinGW/lib/gcc/mingw32/4.7.2/include/c++/mingw32", "-IC:/MinGW/lib/gcc/mingw32/4.7.2/include/c++/backward", "-IC:/MinGW/include"
Some options might be specific to the code base I’m working on but it’s mostly about “-I” options that make things work. Just download MinGW and fed it to clang.

*By “quite good results” I mean that I will see errors highlighted inline in the source. But don’t try to look at the error console (alt+d, alt+p) because there will always be many errors there. I guess because MinGW headers are not fully compatible with clang.

0 Likes

#125

Thanks, I didn’t checked if it’s working. Just thought it doesn’t, as I’ve seen alot of errors.
Now it properly highlights errors in my code and makes correct suggestions for autocomplete. Still, I’m having alot of errors in VS headers, but I’ll ignore that.

0 Likes