Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eclipse IDE: define __cplusplus to build correct index #1010

Closed
euphi opened this issue Aug 5, 2017 · 12 comments
Closed

Eclipse IDE: define __cplusplus to build correct index #1010

euphi opened this issue Aug 5, 2017 · 12 comments
Milestone

Comments

@euphi
Copy link

euphi commented Aug 5, 2017

With the default eclipse configuration created with pio init --ide=eclipse there is no symbol "__cplusplus" defined. Therefore the integrated eclipse indexer cannot handle C++11 standard lib symbols like std::unique_ptr<T>.

To solve this, it helps to define __cplusplus to a recent version, e.g. "201402L".

platformio shall define this by default when initializing a project.

@ivankravets
Copy link
Member

@euphi
Copy link
Author

euphi commented Aug 6, 2017

This does not help the eclipse indexer and it results in a warning from gcc:
<command-line>:0:0: warning: "__cplusplus" redefined [enabled by default]

Honestly, I have no clue how the eclipse indexer really works, but it seems that it uses the default gcc of the local system (and thus not the one installed as pio's platform) to build the index. For some reason I dont't know, it does not enable the latest C++ version by default. Thus, defining __cplusplus for the indexer tool "G++" helps.

This can be done by adding the follwing line to the .cproject file:

<listOptionValue builtIn="false" value="__cplusplus=201402L"/>

in the section of the symbols of the tool "G++":

<tool id="org.eclipse.cdt.build.core.settings.holder.54121539" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">

[.... definition of include paths ...]

  <option id="org.eclipse.cdt.build.core.settings.holder.symbols.1198905600" name="Symbols" superClass="org.eclipse.cdt.build.core.settings.holder.symbols" valueType="definedSymbols">
    <listOptionValue builtIn="false" value="__cplusplus=201402L"/>
  [... definition of other symbols ...]
</option>
</tool>

See also euphi/ESP-LEDCtrl@287fd53 for a commit I did on one of my projects to fix the indexer (be aware that this commit also contents some other cleanup of no longer used include paths etc.).

@euphi
Copy link
Author

euphi commented Aug 6, 2017

@euphi euphi changed the title Eclipse IDE: define __cpluscplus to build correct index Eclipse IDE: define __cplusplus to build correct index Aug 22, 2017
@ivankravets ivankravets added the ide label Feb 8, 2018
@ivankravets
Copy link
Member

Could you reproduce this issue with the latest PIO Core 3.5.1? Please pio upgrade and re-init project.

@JustACatRu
Copy link

Hello.

Could you reproduce this issue with the latest PIO Core 3.5.1? Please pio upgrade and re-init project.

PlatformIO, version 3.6.2
Eclipse IDE for C/C++ Developers Version: 2018-09 (4.9.0) Build id: 20180917-1800

Same problem with "Symbol 'unique_ptr' could not be resolved" and other warnings.
Changing:
...xtensa-lx106-elf-g++.exe ${FLAGS} -E -P -v -dD...
to:
...xtensa-lx106-elf-g++.exe ${FLAGS} -std=c++11 -E -P -v -dD...
in project file "/.settings/language.settings.xml"solves the problem.
It is in "provider" parameter (2 times).

But when I use target "PlatformIO: Rebuild C/C++ Project Index", PlatformIO reverts my changes in "language.settings.xml" :(

As I understand, this file is formed from:
"platformio/ide/tpls/eclipse/.settings/language.settings.xml.tpl"
So, maybe you can just alter this .tpl for eclipse and add "-std=c++11" in it?

@ivankravets
Copy link
Member

See temporary solution here #1010 (comment)

Just add -std=c++11

[env:myenv]
board = ...
build_flags = -std=c++11

Rebuild the project index. Restart Eclipse.

@JustACatRu
Copy link

See temporary solution here...

Thanks for quick reply, but I've tried this and other methods. It does not work.
I've recorded video to show this problem (your solution from 06:50 and my solution from 09:35): https://youtu.be/M2OzvkGHcSQ

Moreover adding "-std=c++11" to "build_flags" results in duplicating "-std=c++11" in build process (it is shown on video from 05:20).

I know, you are busy now. But It will be great, if you will merge my pull request or just add this "-std=c++11" to https://github.com/platformio/platformio-core/blob/develop/platformio/ide/tpls/eclipse/.settings/language.settings.xml.tpl when you'll have free time.

@ivankravets
Copy link
Member

Please re-test with the latest development version via pio upgrade --dev. Don't forget to re-init project.

@JustACatRu
Copy link

Please re-test with the latest development version via pio upgrade --dev. Don't forget to re-init project.

I've re-tested, and there is another error now :(
cxx_path.replace(user_home_dir, '')
changed to:
cc_path.replace(user_home_dir, '')
for some reason.
And adding -std=c++11 not help now.

I've recorded video again for better explanation.
Please, check it: https://youtu.be/ah9Qod0p_I8

Thank you.

@ivankravets
Copy link
Member

Fixed in 286a539

Please repeat pio upgrade --dev and re-init project again.

Does it work now?

@JustACatRu
Copy link

Does it work now?

Checked and...
Yep! Now the problem is solved! :)
PS: can provide video, if needed.

@ivankravets
Copy link
Member

Happy coding with PlatformIO! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants