Author Topic: Code completion with new compiler : no suggestion for header files and classes  (Read 6464 times)

Offline Scr3amer

  • Multiple posting newcomer
  • *
  • Posts: 16
Hello guys,

It has been 2 years now I discovered C::B (and I really appreciate it) and I start to get deeper in C++.
I wanted to try std::thread of C++11 and the bundled TDM 4.7.1 32 bits does not include it.

I downloaded MinGW 4.9.3 SEH POSIX 64 bits compiler and I created a new compiler in the IDE.
I added the right path and created a dummy test program. Here the fun begins ...

When i started to write #include and ctrl-space, no suggestions appeared for standard headers such as iostream or cstdlib.
I had to add the path to C:\MinGW64_4.9.3_POSIX_SEH\x86_64-w64-mingw32\include\c++ into the search directories of the compiler to have right headers.
And if I had C:\MinGW64_4.9.3_POSIX_SEH\x86_64-w64-mingw32\include\c++\tr1, the parser could not do its job because of same name header collision.

Well, I kept only the first path to avoid that collision and I had a partial but functional header autocompletion.
I then added thread header file but when i started to write "std::thr" and then ctrl-space, i had no std::thread suggestion.
I opened the thread file and it had no syntax color like if C::B did not detect it was a valid C++ header.

So no help at all to write my code. When I finally finished my little demo. The compilation went well... At least.

To sum up I have 2 questions :

1)Do we really need to add header folders for new compilers to have header autocompletion for #include (which may lead to suggestion collision and block autocompletion) ? Or is there a canonical way to set-up a new compiler and let C::B detect all the available headers inside the compiler folders and deal with same named headers ? Because in the provided settings of TDM 4.7.1 shipped with C::B, there is no header inclusion and the autocompletion still works and even deals properly with same named headers.

2)Is there a way for C::B to parse properly new headers content ? Or at least a way to force it, help it to do so ? To use the content of these headers in our code : classes, methods, etc.

Thanks in advance for any suggestion, help, idea, tips  :-*

EDIT : I tried with <array>, same thing. When I write std::, no autocompletion. But something new this time, the header has the syntax color.
« Last Edit: October 11, 2015, 04:09:05 am by Scr3amer »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5218
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Here is my test on my own build trunk code, I have a test project, which has "c++ 11" option enabled.
I tested on a 4.7.3 version of GCC (supplied from mingw-build)
See the four screen shot below:
1,


2,


3,


4,


« Last Edit: October 11, 2015, 07:50:55 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Scr3amer

  • Multiple posting newcomer
  • *
  • Posts: 16
 :o

Wonderful ! Ok so I am the problem. What did I do wrong ?

Did you follow a guide to add the new compiler ? Or did you find your own way to do that ? Did you set include folders ? Did you put the compiler in a particular folder ?
When you say your own build trunk, what is its revision ? Can the problem come from the 13.12 version ?
And for c++11, you mean you just checked the right box in the build properties ?

That would be nice of you to have a link or steps to set properly a new compiler *-* !

Thank you for showing me that it is possible to do what I want, you did my day ^^.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11715
    • Travis build status
Can the problem come from the 13.12 version ?
It is possible. Have you tried a nightly?

And 100% you don't need to add anything to the search path to get a completion for stl headers!
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Scr3amer

  • Multiple posting newcomer
  • *
  • Posts: 16
I tried with build 10503 win32.
I used i686-w64-mingw32-gcc-5.2.0 a sjlj POSIX 32 bit compiler.

And when I ran C::B, I had no autocompletion for header files again. But I think I found the reason : the compiler I downloaded does not respect the folder hierarchy of the 4.7.1 TDM.
For instance, iostream is in 5.2.0 : C:\MinGW\i686-w64-mingw32\include\c++
And in TDM 4.7.1 in C:\MinGW\lib\gcc\mingw32\4.7.1\include\c++

When I used TDM 4.7.1, I had again header autocompletion.
But when I used array with it, I activated c++11 in build properties and I still did not have autocompletion for array class  >:( ... The code in the header was "grayed" like if the preprocessor condition of std=c++11 was not met.

I will try with 4.8.1 TDM and other compilers ...
ollydbg I need youuuuu  ;D How did you do that ???

EDIT :
I tried with C::B 4.8.1, C::B 10503 and same MinGW 4.7.3 as ollydbg, I even tried to modify the folder hierarchy but ofcourse the compiler was lost.
I tried on Ubuntu 15.04  with gcc 4.9.2, same thing, you dont have autocompletion for thread, array etc ...
I have no more ideas to obtain this proper autocompletion.
« Last Edit: October 11, 2015, 09:07:21 pm by Scr3amer »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5218
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
EDIT :
I tried with C::B 4.8.1, C::B 10503 and same MinGW 4.7.3 as ollydbg, I even tried to modify the folder hierarchy but ofcourse the compiler was lost.
I didn't modify the folder hierarchy.

Quote
I tried on Ubuntu 15.04  with gcc 4.9.2, same thing, you dont have autocompletion for thread, array etc ...
I have no more ideas to obtain this proper autocompletion.
Normally, if you have "enabled the C++" option in your project or target, then CC will use this option to obtain the correct predefined macros, such as __cplusplus__, which could reflect the C++11 option. Then the parser can parse something like:
Code: [Select]
#if _cplusplus__ > 20110301
#include <thread>
#endif
thus, the header file is parse by our CC's parser.

If you can build C::B from trunk, you can see all the workflows of our CC.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Scr3amer

  • Multiple posting newcomer
  • *
  • Posts: 16
I will try to checkout the latest revision and build it with MinGW 5.2.0. I think that will be painful as it is the first time I do that ^^.
« Last Edit: October 13, 2015, 02:49:05 am by Scr3amer »

Offline osdt

  • Multiple posting newcomer
  • *
  • Posts: 52
I downloaded MinGW 4.9.3 SEH POSIX 64 bits compiler and I created a new compiler in the IDE.

Make sure the new compiler name contains 'GCC' somewhere. Otherwise it may not be recognized as 'GCC based'.

@ollydbg: I've seen some hardcoded 'if (Compiler::GetID().Contains("gcc"))' somewhere in the codebase, don't remember where. Maybe Compiler::GetParentID() could be combined within such conditions.

Offline Scr3amer

  • Multiple posting newcomer
  • *
  • Posts: 16
Yo osdt,

Thanks for your suggestion. I tried renaming the "classic" MinGW build I DL and the one provided by Qt but in both cases, auto-detection fails.
Maybe the way C::B was designed, it recognizes efficiently only TDM compilers files names.

But what I mean is that the biggest problem is not the auto detection failure itself. It is the fact than even if you provide the right folder and executables path for the compiler, even if you check c++11 in the flags, CC does not autocomplete headers names and classes (classic ones or c++11). In my case at least. I tried with 4 computers since Friday.

The classic ones work in my case only when I use the provided TDM compiler. And c++11 CC fails even with provided compilers.

Offline osdt

  • Multiple posting newcomer
  • *
  • Posts: 52
Thanks for your suggestion. I tried renaming the "classic" MinGW build I DL and the one provided by Qt but in both cases, auto-detection fails.
Maybe the way C::B was designed, it recognizes efficiently only TDM compilers files names.

I was talking about the C::B Compiler Name (the default is 'GNU GCC Compiler'). Make a copy (Settings->Compiler->GNU GCC Compiler and hit Copy), name it 'MinGW GCC' or something. Now edit the 'Compilers installation directory' and everything should work.

Offline Scr3amer

  • Multiple posting newcomer
  • *
  • Posts: 16
Oh oki ^^. It did not work too.

@odst By the way, do you save the same problem than mine ? Or am I the only one ?

As a reminder :

->With provided TDM-GCC, I do not have autocompletion with C++11 features like array, even if I enable std=c++11 option in build properties of the project

->With a new compiler I added myself, no header completion nor std::thread and other C++11 classes (when I add manually include path of the new MinGW to have partial header completion) etc.

Maybe I should record a tiny video of the way I create project and set up it and the way I add a new compiler. That may help you to see if I did something wrong.

I downloaded latest revision with SVN, now I try to understand how to set up dependencies because the wxWidget lib I downloaded is very special, with .a .dll but only 2 header files in special folders. And there are lots of projects : x86 or x64, wX2.8 or wX3.0 etc ... I think I will try x86 with TDM 4.7.1.

@ollydbg Were you speaking of this version of MinGW ? http://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.7.3/ ? Because C::B does not recognize it directly on my computer, even if I extract it in C:/MinGW. What is the revision of your screenshot C::B and version of CC ? I think I have these issues because I use an old version of C::B (but why do I have same problem on the build 10503 ?)

Btw, may you upload your C::B build + mingw  as an archive ? So that I can try from my computer ?

EDIT : One of my idea seems correct, detection of TDM-MinGW is better than other MinGW builds : I installed TDM 5.1.0 in MinGW and C::B recognized it immediately, not like what happened with my others MinGW builds. But still no C++11 autocompletion...
« Last Edit: October 13, 2015, 02:51:37 am by Scr3amer »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5218
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Sent from my phone:
Yes, I test exact mingw-build 4.7
I use the trunk head revision
Normally CC use compiler setting from Compiler plugin.
You can open the CC debug dialog to see whether the predefined macros are correct.
See our wiki to know how to open this dialog.
I build wx myself, there's wiki page shows how to build CB.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Scr3amer

  • Multiple posting newcomer
  • *
  • Posts: 16
Ok thanks for the information. Give me 48H, I will be back with what I tried to do :) !

EDIT : Ok I did a trial on an old revision of C::B (9854). i managed to have header autocompletion with different compilers but for c++11, I had to add manually #define __cplusplus 201509L because otherwise CC did not parse properly the preprocessor condtions. Now I will try on last rev.

EDIT 2 : 16-10-2015
I tried the last nightly 10528, code completion works. So it is maybe a problem of the 13.12.

I am still trying to understand why I have some issues with some MinGW toolchains though :
For example, i included iostream but I had no cout in CC with one toolchain (TDM 5.1.0) . I tried another toolchain (4.9.3) and I had cout by CC XD ...

Just one more question : is it normal that __cplusplus macro is updated by CC only when I restart C::B and reopen the project ? I activated c++11, I had 1997 value, I closed and opened C::B and the project and only after that the macro had the right value 2011.


I am still trying to build C::B from source but I have a link error whereas the wxWidget build was OK.
http://forums.codeblocks.org/index.php/topic,19779.0.html

« Last Edit: October 16, 2015, 08:21:17 am by Scr3amer »

Offline norragak

  • Single posting newcomer
  • *
  • Posts: 2
Is there a conclusion? I have some similar problems with mingw-builds' GCC 5.2.0 + Code::Blocks svn 10595.
I've enabled C++14 and added
Quote
D:\mingw\i686-w64-mingw32\include
D:\mingw\i686-w64-mingw32\include\c++
D:\mingw\i686-w64-mingw32\include\c++\bits
respectively into both the global Compiler Settings and Compiler Include Search Paths as well as the project's local Build Options and C/C++ Parser Options Additional Search Paths, and while I've finally got the STL header files like <vector> to be CC'ed, I still can't CC a std::vector.

Weird is that things like std::bad_alloc can be CC'ed. What's going on? Doe this have anything to do with HeaderFixup in Environment Settings?

« Last Edit: December 10, 2015, 01:22:00 pm by norragak »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5218
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Is there a conclusion? I have some similar problems with mingw-builds' GCC 5.2.0 + Code::Blocks svn 10595.
I've enabled C++14 and added
Quote
D:\mingw\i686-w64-mingw32\include
D:\mingw\i686-w64-mingw32\include\c++
D:\mingw\i686-w64-mingw32\include\c++\bits
respectively into both the global Compiler Settings and Compiler Include Search Paths as well as the project's local Build Options and C/C++ Parser Options Additional Search Paths, and while I've finally got the STL header files like <vector> to be CC'ed, I still can't CC a std::vector.

Weird is that things like std::bad_alloc can be CC'ed. What's going on? Doe this have anything to do with HeaderFixup in Environment Settings?
Why do you add those paths manually? Our CC's parser will automatically call the GCC command with the "-E" option, and grab the GCC's search paths.
If you have enabled the C++11, then CC will call GCC command with the C++11 option.
Maybe, you may see the bug here Re: Release 15.12, RC1 has arrived, I'm going to commit a fix soon.
« Last Edit: December 10, 2015, 02:58:22 pm by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5218
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
...
Maybe, you may see the bug here Re: Release 15.12, RC1 has arrived, I'm going to commit a fix soon.
Done in rev10618. You guys can test it if you can build c::b from source yourself.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline norragak

  • Single posting newcomer
  • *
  • Posts: 2
Why do you add those paths manually? Our CC's parser will automatically call the GCC command with the "-E" option, and grab the GCC's search paths.
If you have enabled the C++11, then CC will call GCC command with the C++11 option.
Maybe, you may see the bug here Re: Release 15.12, RC1 has arrived, I'm going to commit a fix soon.
Thanks for the tip. I added the paths and kept them there back in some old days when CC couldn't even sometimes locate the C++ headers. It used to work until I updated my compiler toolchain and the IDE. It looks like things have changed, maybe somehow improved as removing them actually solves my old and new problems here. I might give the latest svn a try when I get the time to.