Sublime Forum

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

#100

RyanJ, You could compile libcache (and possibly libclang too) yourself with debug symbols enabled, and you should be able to attach a debugger to Sublime Text 2 and get a proper stacktrace for this issue.

0 Likes

#101

FYI, it looks like one of your recent changes seems to have fixed the issue I was seeing. If I do see it again I’ll build the libs to debug it more (I’d been too busy to attempt that yet).

so… thanks! :smiley:

0 Likes

#102

Cool, thanks for the update :smile:

0 Likes

#103

edit:

Never mind. It did find my include files, but it throws numerous errors on the new header files from the Windows 8 SDK, so I’ll just leave it for now and try again later.

0 Likes

#104

Hey folks,

I’m trying to get SublimeClang to play friendly with Objective-C. I’ve followed the suggestions on this forum and the GitHub Page and added the following to my “options”:

"/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.2.sdk", "-D__IPHONE_OS_VERSION_MIN_REQUIRED=40300", "-I/Users/CVSS/Documents/Reader"

However, I still get the following error when I open a file in my project:

Fatal - 'UIKit/UIKit.h' file not found Did you configure the include path used by clang properly? See http://github.com/quarnster/SublimeClang for more details on how to configure SublimeClang.

I’m using the latest SDK, lateste build of ST2 and Running on Lion.

Any ideas? Thanks.

0 Likes

#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