Sublime Forum

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

#65

+1 tiktaalik

My project tree :

~/myproject/Makefile
~/myproject/src/*.cpp
~/myproject/include/*.hpp

My project’s settings :

{
	"settings":
	{
		"sublimeclang_options":
		
			"-W",
			"-Wall",
			"-Wextra",
			"-Werror",

			"-I${home}/myproject/include",

			"-I/usr/lib/clang/3.0/include/",
			"-I/usr/lib/clang/2.1/include/",
			"-I/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/",
			"-I/usr/lib/gcc/i686-apple-darwin11/4.2.1/include/"
		]
	},
	"folders":
	
		{
			"path": "myproject"
		}
	]
}

What’s wrong?

0 Likes

#66

Try clearing the cache (alt+d,alt+c) and if that doesn’t work open up sublimeclang.py and add a “print opts” before the return in the function “get_opts”. Then check the python console for what options are actually used to see if that gives you any clues.

0 Likes

#67

That still doesn’t work. I tried everything (absolute, relative path, in my projects settings and in general settings of sublimeclang …)

0 Likes

#68

I have the same issue as GMath. I’m less informed than he is probably. Could anyone help me?

My current setup below-
*(http://i.imgur.com/dYtSz.jpg)

Windows 7 64, running ST2 32bit*

0 Likes

#69

[quote=“JesseMeyer”]I have the same issue as GMath. I’m less informed than he is probably. Could anyone help me?

My current setup below-
(http://i.imgur.com/dYtSz.jpg)
That spaces in path look suspicious. Maybe try to move project to path without spaces.[/quote]

0 Likes

#70

Thanks for the suggestion. Unfortunately, after removing spaces (and other “special” characters) from both the directories and the include paths, and clearing the cache, the problem persists.

0 Likes

#71

I’m very thankful to the author of this excellent plugin! I’d add the following to the list of suggestions:

]When a header with #pragma once is analyzed, clang emits a warning #pragma once in main file As I can reason after skimming through the sources of clang, that warning can’t be disabled per se, only with -w and the like, which can obviously be an overkill. Maybe the plugin could filter out such warnings when analyzing headers (or any sources, really, it wouldn’t harm)./]
]Don’t know if that’s possible, but it would be great if the clang output window doesn’t pop out during the build, thus preventing to see whether the build was successful./]

0 Likes

#72

Is it possible that the “new” autocompletion present in the recent build will interfere with SublimeClang?

I was able to configure one of my smaler projects to generate a valid cache and I (sometimes) have completion
but along the clang-completion there seems to be the normal autocomplete list. In some cases this seems to
go as far as completely replacing the clang completions (you can distinguish them by the type-signature in the completion).

I really think this plugin is a great idea - I’ve been using something similar on vim for quiet some time now.

One other thing I notice is that SublimeClang sometimes - without a reason - claims no to find a header it was
finding five minutes ago without any problems. Is there any way (or line of code) I can use to get the plugin to
display what it is passing to clang so I can check if my paths are configured correctly?

P.S. I’m able to test against linux / osx clang (3.1)

0 Likes

#73

[quote=“mnus”]Regarding Linux errors

I’m running Ubuntu 11.10 64bit. I was able to get this plugin working by symlinking /usr/lib/python2.6/ to sublime2’s lib directory, and recompiling libclang.so to target a 64bit architecture.

1.) Install python2.6 via apt-get or synpactic.
2.) Backup python26.zip in sublime2’s lib directory (just for safe measure). I did mv “python26.zip backup.python26.zip”
3.) Symlink /usr/lib/python2.6/ to sublime2’s lib directory.
4.) Download and compile clang. (You can probably get away with installing clang from the ubuntu repos)
5.) Copy libclang.so from the installed location into /.config/sublime-text-2/Packages/SublimeClang/

I’m still left with the issue of Clang not being able to find “stdarg.h”, but I believe that’s a clang bug and has nothing to do with this plugin.

Note to the the author of this plugin: It’s probably best not to include the compiled library for linux in your repository, given that each architecture requires its own build. It may be a better idea just to have a text file instructing linux users to build and copy libclang themselves. Thanks for this awesome plugin![/quote]

I’m using openSUSE 12.1 with python2.7. And I did the symlink by running the command:

# ln -s /usr/lib/python2.7/ /usr/share/SublimeText2/lib/

It did work for the plugin, as the “ctypes” error message no longer appear.
However, other problems arose after I’ve done the linkage. When I start st2 from Konsole(/usr/share/SublimeText2/sublime_text), an error message is shown in the Konsole:

'import site' failed; use -v for traceback

while the st2 is still able to run.
And the terminal inside st2 shows much more error messages:

Traceback (most recent call last): File "./sublime_plugin.py", line 1, in <module> import os ImportError: No module named os plugin init time: 0.116299 loading bindings loading pointer bindings found 1 files for base name Default.sublime-theme theme loaded app ready pre session restore time: 0.213486 using gamma: 1 (err: 0) AttributeError: 'module' object has no attribute 'on_activated'
The Clang did not work well once I did the linkage, and it’s the same when I did the linkage to python2.6 in another folder. So the solution seems dose not work at my laptop.
Hope the problem could be solved in next update~

0 Likes

#74

Try to use “//” or “\” instead of “” for Windows.

[quote=“tiktaalik”]

[quote=“quarnster”]
Try removing the first “/” before D:[/quote]

Tried this but didn’t have an effect. Currently looks like so:

"-ID:/blah/MadScience/Project/blahproj/dev/Package/", "-ID:/blah/MadScience/Project/blahproj/dev/Source/"[/quote]

0 Likes

#75

There seems to be a problem with the latest build of Sublime Text (2181) and this plugin. Per-project settings don’t work at all and the Sublimeclang error pane makes the caret disappear and re-appear every time you move it while the pane is visible. Downgrading to 2165 resolves these issues.

0 Likes

#76

Under Windows to autocomplete filenames in my ‘include’ directories (like stdio.h) I’ve added these lines to my ‘SublimeClang.sublime-settings’ file (in “options” section) as below:

“options”:

  ....
     .
     .
     .

    //include path for minGW
    ,"-IC:\\Program Files\\MinGW\\include"
    ,"-IC:\\Program Files\\MinGW\\lib\\gcc\\mingw32\\4.6.1\\include"
],

Nice coding!
(I’ve typed commas first to know which line is added to the file and to remove just the lines if needed)
P.S. Your ‘SublimeClang.sublime-settings’ file is in ‘%Appdata%\Sublime Text 2\Packages\SublimeClang’ folder.

0 Likes

#77

[quote=“sujz”]Try to use “//” or “\” instead of “” for Windows.

[quote=“tiktaalik”]

Tried this but didn’t have an effect. Currently looks like so:

"-ID:/blah/MadScience/Project/blahproj/dev/Package/", "-ID:/blah/MadScience/Project/blahproj/dev/Source/"[/quote]

On Windows I have found that you should not have a trailing ‘/’ in the path. Additionally I tend to use ‘\’ instead of ‘/’ because ‘’ is the native character on Windows for file separation (and because its an escape character you need two of them).

0 Likes

#78

I thought I’d replied previously but it looks otherwise - thank you for adding this feature, it is proving to be very useful.

0 Likes

#79

[quote=“adn”]Under Windows to autocomplete filenames in my ‘include’ directories (like stdio.h) I’ve added these lines to my ‘SublimeClang.sublime-settings’ file (in “options” section) as below:

“options”:

  ....
     .
     .
     .

    //include path for minGW
    ,"-IC:\\Program Files\\MinGW\\include"
    ,"-IC:\\Program Files\\MinGW\\lib\\gcc\\mingw32\\4.6.1\\include"
],

Nice coding!
(I’ve typed commas first to know which line is added to the file and to remove just the lines if needed)
P.S. Your ‘SublimeClang.sublime-settings’ file is in ‘%Appdata%\Sublime Text 2\Packages\SublimeClang’ folder.[/quote]

This works for me very well but I get a lot of errors from mingw files like this:
img651.imageshack.us/img651/3976 … 181953.png

Any solution to fix/disable this ?

Temporarily i set show_output_panel to false to disable this annoying errors.

My options:

  "options":
  
    "-Wall",
    "-Wextra",
    "-ferror-limit=0",
    "-IE:/Dev/Tools/MinGW64/include",
    "-IE:/Dev/Tools/MinGW64/lib/gcc/x86_64-w64-mingw32/4.6.1/include",
    "-IE:/Dev/Libs/gmock-1.6.0/include",
    "-IE:/Dev/Libs/gmock-1.6.0/gtest/include",
    "-IE:/Dev/Libs/glfw-2.7.2/include",
    // projects paths here
  ]
0 Likes

#80

First of all, thanks for a great plugin!

I have stumbled upon a very annoying problem, that forces me to disable auto completion. :cry:

The problem I have is that auto completion does not seem to understand anonymous unions.
The library i’m trying to use has a struct that contains a type and a union with type dependent data.
The problem is that the type will always be auto completed (like there was no other members in the struct).
This makes it impossible to write code to access the members within the union.

I supply a minimal code example that can reproduce the problem.

struct MyStruct
{
   int type;
   union
   {
      int value_int;
      double value_double;
   };
};

int main(int argc, char const *argv])
{
   struct MyStruct my_struct;

   // try to use my_struct here with autocompletion enabled.
   // type is always auto completed and it is impossible
   // to write code to access value_int or value_double with auto complete enabled.

   return 0;
}
0 Likes

#81

I’ve opened an issue for this on the SublimeClang homepage: github.com/quarnster/SublimeClang/issues/54

BTW, you can toggle the plugin on and off via the default keybinding alt+d,alt+t.

0 Likes

#82

This has now been fixed.

0 Likes

#83

Great! Thanks for the super quick fix!

0 Likes

#84

I’ve been reading through this thread and am still wondering if there is a definitive answer on whether or not clang autocomplete works properly on Windows 64 Sublime 2 using MinGW for C++ STL. I have the following in my User Options for SublimeClang:

[code]{
“options”:

    "-Wall",
    "-IC:\\MinGW\\include",
    "-IC:\\MinGW\\lib",
    "-IC:\\MinGW\\lib\\gcc\\mingw32\\4.6.2\\include\\c++",
    "-IC:\\MinGW\\lib\\gcc\\mingw32\\4.6.2\\include\\c++\\mingw32"
]

}
[/code]

and while it looks like the plugin is doing something, I keep getting the following error:

C:\MinGW\include\wchar.h:26,10 - Fatal - ‘stddef.h’ file not found

stddef.h is sitting in C:\MinGW\lib\gcc\mingw32\4.6.2\include and when I alter the options to include that directory, the previous error goes and I am confronted with:

C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++\cwchar:145,11 - Error - no member named ‘fgetws’ in the global namespace
C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++\cwchar:147,11 - Error - no member named ‘fputws’ in the global namespace
C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++\cwchar:151,11 - Error - no member named ‘getwc’ in the global namespace
C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++\cwchar:152,11 - Error - no member named ‘getwchar’ in the global namespace
C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++\cwchar:157,11 - Error - no member named ‘putwc’ in the global namespace
C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++\cwchar:158,11 - Error - no member named ‘putwchar’ in the global namespace
C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++\bits/basic_ios.h:249,26 - Error - expected ‘)’
C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++\bits/basic_ios.h:249,17 - Note - to match this ‘(’

Any suggestions would be greatly appreciated.

0 Likes