Sublime Forum

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

#105

I’m currently trying to get SublimeClang to work on my Windows notebook, but somehow I can’t (be aware, I’m not really a C++ pro :wink:).
I already figured out that somehow the header include paths are hard coded and therefore don’t match my GCC 4.7.0 installation under C:\MinGW\lib\gcc\mingw32\4.7.0 so I create an NTFS symlink from C:\MinGW\lib\gcc\mingw32\4.7.0 to C:\MinGW\lib\gcc\mingw32\4.6.2 which seems to work.
Alternatively I could pass the parameters -IC:/MinGW/lib/gcc/mingw32/4.7.0/include/c++ -IC:/MinGW/lib/gcc/mingw32/4.7.0/include/c++/mingw32 -IC:/MinGW/lib/gcc/mingw32/4.7.0/include/c++/backward each time when calling clang++ to get it to compiling something without telling me that it can’t find the headers files (which is quite tedious, of course).

But in Sublime Text neither of these solutions work. I always get the message, that some header file (e.g. ) could not be found. And when I add this to my user config:

[code]{
“options”:

    "-Wall",
    "-IC:/MinGW/lib/gcc/mingw32/4.7.0/include/c++",
    "-IC:/MinGW/lib/gcc/mingw32/4.7.0/include/c++/mingw32",
    "-IC:/MinGW/lib/gcc/mingw32/4.7.0/include/c++/backward"
]

}[/code]It can find that file, but then I get the message:

[quote]C:/MinGW/lib/gcc/mingw32/4.6.2/include/c++\cwchar:46,10 - Fatal - ‘wchar.h’ file not found
Did you configure the include path used by clang properly?
See github.com/quarnster/SublimeClang for more details on how to configure SublimeClang.[/quote]

What am I doing wrong?

I have MinGW installed to C:\MinGW and Clang to C:\MinGW\clang. Both their bin directories are in my $PATH variable. Compiling with clang works fine. Only SublimeClang does not.

Another issue:
I also tried installing SublimeClang on my Linux workstation, but that doesn’t work either. Building Python 2.6 fails with the message:

[quote]gcc: error: directory": No such file or directory
make: *** [Modules/getbuildinfo.o] Error 1[/quote]

And BTW what do I need Python 2.6 for? Why doesn’t it work Python 2.7 as well, which is installed anyway?

Would be great if someone could help me out with this.
Thanks. :smile:

0 Likes

#106

I’m trying to get SublimeClang to work for my dev setup. I’m currently running under Ubuntu 12.04, and have followed the instructions on the github page for installation/configuration. Whenever clang attempts to parse files, I keep getting an error like this:

sublime_text: /home/jasedit/.config/sublime-text-2/Packages/SublimeClang/src/build/llvm/tools/clang/lib/Lex/PreprocessingRecord.cpp:256: clang::PreprocessingRecord::PPEntityID clang::PreprocessingRecord::addPreprocessedEntity(clang::PreprocessedEntity*): Assertion `(PreprocessedEntities.empty() || !SourceMgr.isBeforeInTranslationUnit(BeginLoc, PreprocessedEntities.back()->getSourceRange().getBegin())) && "a macro directive was encountered out-of-order"' failed.
libclang: crash detected during parsing: {
  'source_filename' : '(null)'
  'command_line_args' : '-I/home/jasedit/.config/sublime-text-2/Packages/SublimeClang/clang/include', '-I/home/jasedit/project1/include', '-I/home/jasedit/project1/externals/include', '-x', 'c++', '/home/jasedit/project1/src/Main.cpp'],
  'unsaved_files' : ],
  'options' : 13,
}

Every time it attempts to parse a file. I’m not entirely sure what’s going on here, but I’m not getting any auto-completion results. Any ideas?

0 Likes

#107

I use Windows 7 x64, Sublime Text 2 dev channel, build 2216, MinGW 4.7.0


Clang analysis shows errors in headers mingw, but i compile the project with mingw32-g++ without errors or warnings.
Sorry for my english.

0 Likes

#108

My guess is missing include paths or a missing preprocessor define.

0 Likes

#109

Am I missing smth, but where is the autocompletion? I’ve passed headers path to the plugin (include in 10.8 SDK folder under the xcode.app) but still nothing is being autocompleted. Is there a way to get full-featured autocompletion like xcode and VS have? It’s so inconvenient to open a manpage every time I need to call a function =. No, srsly, how can people work this way? :open_mouth:
PS
I’m talking about plain C autocomplete. You now, strlen, sprintf, mkfifo, other stuff.

0 Likes

#110

My bad. Opened an issue: github.com/quarnster/SublimeClang/issues/136.

0 Likes

#111

[quote=“RyanJ”]

My guess is missing include paths or a missing preprocessor define.[/quote]

Yes. This is my experience after spending a couple of days fiddling with the plugin to get everything working, hope it helps someone.

Turning off the error limit (-ferror-limit=0) is helpful for debugging this kind of stuff.

To fix the winbase.h DECLSPEC_NORETURN error add the define GNUC=4

To fix “no member named ‘fgetws’ in the global namespace” etc in cwchar when using add the define MSVCRT

Include paths will vary by MinGW distribution and/or version, this is what works for me using the 4.7.2 package from nuwen.net;

[code] “options”:

"-ferror-limit=0",
"-D__GNUC__=4",
"-D__MSVCRT__",
"-isystem", "C:\\MinGW\\lib\\gcc\\i686-pc-mingw32\\4.7.2",
"-isystem", "C:\\MinGW\\lib\\gcc\\i686-pc-mingw32\\4.7.2\\include",
"-isystem", "C:\\MinGW\\lib\\gcc\\i686-pc-mingw32\\4.7.2\\include-fixed",
"-isystem", "C:\\MinGW\\include",
"-isystem", "C:\\MinGW\\include\\c++\\4.7.2",
"-isystem", "C:\\MinGW\\include\\c++\\4.7.2\\i686-pc-mingw32",
"-Wall"

]
[/code]

Great plugin, thanks very much :smile:

0 Likes

#112

And now a question. Is there any way to get the plugin to provide auto-complete parameters for functions defined as a macro?

E.g. In the windows headers any function that takes a string has two versions, which are selected based on whether UNICODE is defined or not;

WINUSERAPI int WINAPI MessageBoxA(HWND,LPCSTR,LPCSTR,UINT);
WINUSERAPI int WINAPI MessageBoxW(HWND,LPCWSTR,LPCWSTR,UINT);

#ifdef UNICODE
#define MessageBox MessageBoxW
#else
#define MessageBox MessageBoxA
#endif

The auto-complete will show the MessageBox macro at the top of the list, but choosing it just enters MessageBox with no parameters. I have to go down the list and select MessageBoxA or MessageBoxW to get the parameters, which is a bit annoying.

0 Likes

#113

Hi guys.

First, thank you quarnster (and any other developer I’m not aware of) for this incredibly useful plugin.

I’m attempting to switch from VS to Sublime for all my C++ coding needs on Win7. I’ve successfully built my C++ code from within SLT2 using MSVC. The functionality I miss the most that’s left to integrate is code competition / checking. I’ve been following this plugin for awhile and unfortunately I do not know enough to figure this one out. I’ve researched and have attempted numerous times but to no avail. Please help.

I’m writing a game and have my code separated into two directories under a single folder.

F:/Game/EngineCode
“” / “” /GameCode

My VS install is standard.

Whenever I open a game source file, clang freaks out claiming that it cannot find any includes. Here is my sublime options and project settings.

[code]{
“folders”:

	{
		"path": "/F/C4-2.10/VisualStudio2012/C4"
	},
	{
		"path": "/F/C4-2.10/EngineCode"
	},
	{
		"path": "/F/C4-2.10/GameCode"
	}
],

"settings":
{
	"sublimeclang_options":
	
    	"-IF:/C4-2.10/EngineCode"
	]
}

}[/code]


    "options":
    
        "-isystem", "F:/C4-2.10/EngineCode",
        "-IF:/C4-2.10/GameCode",
        "-ferror-limit=0",
        "-Wall"
    ],

And for the strange part. In my game code, sometimes it will report the file locations with their directory slash reversed. It’s not uncommon to see

F:\Game\GameCode/someFile.h:19,10 - Fatal - ‘someInclude.h’ file not found (“someInclude” is not ever in the same directory as “someFile”).

If anyone would assist I’d be very grateful.

Thank you in advanced.

JM

0 Likes

#114

I absolutely love SublimeCLang!
One question: “sometimes”, SublimeCLang slows down the whole ST2. I mean: on a project that is normally working fine… at some point in time using CLang blocks ST2 every time I press a letter, waiting for the autocomplete. This is due to Clang, since if I disable it, (“enabled”: false) everything works
Sometimes, I also get messages from ST2 saying “A plugin clang is locking ST…” (or something similar).

I know my question is quite “vague”, but I have no further details, nor ideas what to look for…

Thank you in advance for any help.

0 Likes

#115
  1. I wonder if it’s possible to use clang plugins with SublimeClang (or maybe question should be: is it possible to use plugins with libclang?). I can’t get it to work after specifying appropriate arguments to clang. For example:
-Xclang -load -Xclang ../BoolCheck.so -Xclang -add-plugin -Xclang boolcheck -Xclang -plugin-arg-boolcheck -Xclang -load-type-list -Xclang -plugin-arg-boolcheck -Xclang test-bools

as mentioned here: blog.mozilla.org/mwu/2011/07/28/ … f-mozilla/ (note that I have not tried this specific plugin).

  1. Connected to above, is it possible to configure SublimeClang to spew out all kind of output that clang would spew out? For example, if normal clang executable fails to load the plugin, it might say something in the standard output. With libclang I think it only outputs stuff it was asked for (or maybe it is filtered by SublimeClang?).
    That could be also useful for seeing more detailed information about warnings or errors that standalone clang tends to produce.
0 Likes

#116

SublimeClang works nicely on Windows with Visual C++ after adding the VC++ and Windows SDK include folders to the search path.

Excellent plugin! Thanks!

0 Likes

#117

Hi, is there a way to change brackets position when autocomplete is used? For example, when I use autocomplete for the if keyword I get

if (/* condition */)
{
  /* code */
}

but I would prefer the following (default style in SublimeJava):

if (/* condition */) {
  /* code */
}

Thanks for the help :smile:

0 Likes

#118

I suspect this is just the default snippet, that you can amend:

<snippet> <description>If Condition</description> <content><![CDATA[if (${1:/* condition */}) { ${0:/* code */} }]]></content> <tabTrigger>if</tabTrigger> <scope>source.c, source.objc, source.c++, source.objc++</scope> </snippet>

[in the C++ folder.]

0 Likes

#119

It worked, thank you very much :smile:

0 Likes

#120

Hi,

I have an issue with SublimeClang when using multiple cursors. Let me use an example :

Let say I have 4 functions

func1|
func2|
func3|
func4|

With for cursors at the end of the line.
if I hit space, the cursors will take a different position, shifting the positions to 1 character each line, like this

func1 |
func |2
fun |c3
fu |nc4

I only have this issue when Clang is enable.

So if anyone have an idea …

Thank you.

0 Likes

#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