Code::Blocks

User forums => Help => Topic started by: AbdelrahmanSaid on June 08, 2020, 02:43:36 am

Title: Inconsistent autocomplete behavior between Windows and Linux
Post by: AbdelrahmanSaid on June 08, 2020, 02:43:36 am
I am having strange issues when using Code::Blocks in Linux Mint 19.

For instance, if I include the string class and try to declare a string varaible by typing std::string, the autocomplete doesn't show string. It only shows stringbuf and stringstream. The code still works as expected, it just doesn't show in the autocomplete.

Additionally, the autocomplete doesn't work for any of the methods under the string class. For instance, if I have a string variable called str, and then I type str.find, the autocomplete won't appear at all. If I press Ctrl+Space, nothing would happen.

None of these issues happen on Windows.

The reason I need the autocompletion is that I am still new to C++, so having a good autocomplete function helps me a lot.

Any ideas why I am having these weird issues?
Title: Re: Inconsistent autocomplete behavior between Windows and Linux
Post by: huycan on June 10, 2020, 01:09:18 am
I tested it under Linux Mint 19.3 Xfce.... and it works fine...
Title: Re: Inconsistent autocomplete behavior between Windows and Linux
Post by: stahta01 on June 10, 2020, 01:49:09 am
I tested it under Linux Mint 19.3 Xfce.... and it works fine...

This implies it is an missing Linux package or an C::B setting issue.

To the OP: Did you try installing dev pckages related to the missing features?

huycan: Do you have any special settings to make auto completion work in C::B?

Edit2: AbdelrahmanSaid: You did include the correct header, right?

Tim S.
Title: Re: Inconsistent autocomplete behavior between Windows and Linux
Post by: huycan on June 10, 2020, 02:41:57 am
Ok.... The problem is with the gcc compiler came with Linux Mint 19.3 ... Mine is the gcc 9.3 that I built myself... and that version's working fine... I tested by switching back to gcc 7.5 (came with Linux Mint) and voila... the problem happened just like the OP described....
Title: Re: Inconsistent autocomplete behavior between Windows and Linux
Post by: AbdelrahmanSaid on June 10, 2020, 03:22:09 am
Thanks for the help, guys. I haven't tested with other versions of the compiler as I only have the one that comes by default at the moment.

Any ideas how can I fix this issue with the current compiler, or do I need to install a new version?
Title: Re: Inconsistent autocomplete behavior between Windows and Linux
Post by: huycan on June 10, 2020, 03:30:54 am
I did try to upgrade the compiler manually by

Code: [Select]
sudo apt-get install gcc-8 g++-8
(They don't have 9 yet... and the current version is 10...)

Anyway, the problem still persists...

So, you might try to build the latest gcc from source....

Side note: I tried on Ubuntu 20 ... (it comes with gcc 9.3) and there is no problem...
Title: Re: Inconsistent autocomplete behavior between Windows and Linux
Post by: BlueHazzard on June 10, 2020, 09:25:03 am
How have you installed the  self build gcc?
I think this is some search path issue for the code completion...
Title: Re: Inconsistent autocomplete behavior between Windows and Linux
Post by: AbdelrahmanSaid on June 10, 2020, 10:47:20 am
I confirm the behavior. I have done a quick test upgrading to gcc-9 from the ubuntu testing repositories and codeblocks immediately started working as expected.

I think this is some search path issue for the code completion...

Any ideas on how to fix it if it is indeed a search path issue?
Title: Re: Inconsistent autocomplete behavior between Windows and Linux
Post by: huycan on June 10, 2020, 02:14:41 pm
How have you installed the  self build gcc?

Use the current gcc compiler in your system and build the new one from the source... It is a lot easy (more straight forward) to do it in Linux than Windows...
Title: Re: Inconsistent autocomplete behavior between Windows and Linux
Post by: BlueHazzard on June 10, 2020, 05:03:23 pm
Quote
Use the current gcc compiler in your system and build the new one from the source... It is a lot easy (more straight forward) to do it in Linux than Windows...
The question was more, how did you use it in codeblocks. How did you give codeblocks the paths... Did you created a package and installed it, or did you used configure --prefix or did you used the default for configure....
installing is not building...
Title: Re: Inconsistent autocomplete behavior between Windows and Linux
Post by: AbdelrahmanSaid on June 10, 2020, 05:36:40 pm
Quote
Use the current gcc compiler in your system and build the new one from the source... It is a lot easy (more straight forward) to do it in Linux than Windows...
The question was more, how did you use it in codeblocks. How did you give codeblocks the paths... Did you created a package and installed it, or did you used configure --prefix or did you used the default for configure....
installing is not building...

I have just finished doing it. Built gcc-9.3 from source and started using it in codeblocks and it works perfectly.

To do that, all you need to do is, in codeblocks, go to Settings > Compiler, choose the 'Toolchain Executables' tab and point codeblocks to where you have installed the new version of gcc. That is what I have done and it seems to work perfecctly fine for me.
Title: Re: Inconsistent autocomplete behavior between Windows and Linux
Post by: huycan on June 10, 2020, 08:57:46 pm
Actually, you don't have to change any setting in CodeBlocks. I just create a script to change all the soft links in /usr/bin point to appropriate version.... for example, /usr/bin/gcc points to gcc-9.3 instead of gcc-7.5, g++ points to g++-9.3 , etc...  This way, your whole system is using the 9.3 version (even if you use different IDE)... and if you want to switch back to older version, change the links.
Title: Re: Inconsistent autocomplete behavior between Windows and Linux
Post by: AbdelrahmanSaid on June 10, 2020, 10:43:07 pm
Actually, you don't have to change any setting in CodeBlocks. I just create a script to change all the soft links in /usr/bin point to appropriate version.... for example, /usr/bin/gcc points to gcc-9.3 instead of gcc-7.5, g++ points to g++-9.3 , etc...  This way, your whole system is using the 9.3 version (even if you use different IDE)... and if you want to switch back to older version, change the links.

Yeah.. of course that would be the other option here. I just didn't want to change the gcc version that my system uses, so I switched it in codeblocks.
Title: Re: Inconsistent autocomplete behavior between Windows and Linux
Post by: AbdelrahmanSaid on June 10, 2020, 11:46:31 pm
Okay. I have encountered another strange issue.

When I declare a variable, let's say an integer called num. If I initialise it with the assignment operator, i.e. int num = 0;, then everything works fine.

However, if initialise it like this int num {0};, then codeblocks would not take that variable into consideration for code completion. If I type start typing the name of the variable, the auto code completion won't appear, and if I try to force it with Ctrl+Space, then codeblocks won't find it. Additionally, if the variable has methods, a string or a vector variable for instance, then none of these methods would show up, because the variable isn't even recognised as a variable.

Any ideas what is happening here?
Title: Re: Inconsistent autocomplete behavior between Windows and Linux
Post by: oBFusCATed on June 10, 2020, 11:48:54 pm
Any ideas what is happening here?
The CC hasn't been updated to support the stupidly broken modern initialization style which doesn't work (tm) :)
Patches welcome.
Title: Re: Inconsistent autocomplete behavior between Windows and Linux
Post by: AbdelrahmanSaid on June 11, 2020, 12:11:20 am
Any ideas what is happening here?
The CC hasn't been updated to support the stupidly broken modern initialization style which doesn't work (tm) :)
Patches welcome.
I see. That is what I suspected. Thanks for confirming that.

I personally prefer using the assignment operator anyway, so I will probably stick to it. It is just I am still fairly new to C++, and the course I am following uses the list initialisation most of the time, so I end up using it a lot when I am following some of the course material.

Since I am still learning, you probably wouldn't want my patches at the moment ;D. Joking aside, would love of course to contribute back once I am comfortable with C++.

Thanks again for clearing this up.