cancel
Showing results for 
Search instead for 
Did you mean: 

CubeIDE: Imported Eclipse 'C' Project incorrectly defines __cplusplus

STM32 CubeIDE v1.5.1; Build: 9029_20201210_1234 (UTC)

The same Eclipse Project as:

https://community.st.com/s/question/0D53W00000Y2lIsSAJ/cant-usecreate-debug-config-for-oss7-stack

It is a 'C' Project, but the CubeIDE defines __cplusplus:

0693W000007ZDYEQA4.png 

Which, as you can see, messes-up the codes checks to see if C++ is being used!

If I manually delete that definition, all is fine.

The problem does not happen when opening the project in a "normal" Eclipse Neon 3.

So why is CubeIDE adding this?

33 REPLIES 33
mattias norlander
ST Employee

Looked at your links but was still not able to find the project. Could you provide direct link to download project?

Q1: If you open the .project-file in the original project (before importing it into CubeIDE). Does it contain the node: <nature>org.eclipse.cdt.core.ccnature</nature> ??

  • cnature is only C project
  • ccnature is a C/C++ project

Q2: If you import the project into CubeIDE. Now open the .project-file, does it now contain the ccnature node?

If CubeIDE for some reason adds C++ to the project file, then it sounds like a bug. If it is part of the original content, then I would guess this is expected?!

If ccnature. then the C++ compiler is also setup for the project, and then the C++ compiler would set up the symbol "__cplusplus=201402L", assuming you are using -std=gnu++14.

Need som more info/answers...

You're right: it's not supplied as a "ready to go" project - you have to create the project by running CMake.

I'll take a look at the ccnature thing, and make a project to upload...

OK, the freshly-created Eclipse Project contains:

	<natures>
		<nature>org.eclipse.cdt.make.core.makeNature</nature>
		<nature>org.eclipse.cdt.make.core.ScannerConfigNature</nature>
		<nature>org.eclipse.cdt.core.ccnature</nature>
		<nature>org.eclipse.cdt.core.cnature</nature>
	</natures>

So, yes: it does contain a "ccnature" - and also a "cnature"

I just opened this in CubeIDE by double-clicking the .project - and this time it has not defined __cplusplus !

Projects attached:

  • .orig suffix are originals as generated by CMake;
  • .cube suffix are after being opened by CubeIDE.

mattias norlander
ST Employee

I am not sure that the approach is good to start with. CMake does have some support to generate Eclipse project. But to my understanding this part of CMake is not well-maintained. If I do a quick google on "CMake generate Eclipse projects" most search hits are a decade old...

It may be more safe to have CMake generate only a makefile and create a CubeIDE project that uses this "CMake managed makefile" to build your resources. Removes one layer of complexity, maybe at the cost of adding another ;)

This approach should be possible in CubeIDE 1.6.0. First as always make back-up of your project....

Then try this:

  1. File > New > Makefile project with Existing Code
    1. Give a name
    2. Point to the project location
    3. Select MCU ARM GCC
  2. OK - you will now have to make sure that the makefile is found by the build system.
    1. Hint, check: Project Properties > C/C++ Build > Builder Settings > Build directory
  3. Once you have a working makefile you probably want to debug as well...
  4. To make debug work the debugger integration needs to know which MCU you are targeting. Because of a known issue in CubeIDE 1.6.0, you have to perform a little stunt:
    1. Project Properties > C/C++ Build > Builder Settings > Check "Generate Makefiles automatically".
    2. Click Apply
    3. WARNING: Do NOT build your project until step 7 is finished!! If you do, the managed build system will overwrite your makefiles!
    4. This will expose a hidden GUI:
    5. Project Properties > C/C++ Build > Settings > Tool Settings > MCU Settings > Select.
      1. Browse for your MCU select it and click Apply.
    6. Go back to Project Properties > C/C++ Build > Builder Settings > and Uncheck "Generate Makefiles automatically".
    7. Click Apply.
  5. All done. If you create a debug config now you should be able to debug the target... If you instead tried to launch the debug session without performing step 4 you will get tons of errors messages...

Is this a better way forward? It may have both pros and cons. We are always interested in feedback...

Made some edits to clarify the process after reading @Pavel A.​  post. Will see if i can setup a virtual Ubuntu machine in home office to re-produce.

Hi @mattias norlander​ 

Your advise unfortunately does not work here on Ubuntu...

We have an existing makefile project.

Checked "Generate Makefiles automatically".

0693W000007ZvQnQAK.png 

But this does not enable " MCU Settings"

0693W000007ZvQOQA0.pngPlease advise ? Is this working only on Windows or only for newly created makefile projects?

0693W000007ZvS5QAK.png 

Thanks,

Pavel

Answering my own question...

* The trick to specify the MCU requires to create a new CubeIDE makefile project, as in the Mattias' post above.

* Folks who have any other Eclipse makefile - based projects, can take them and *** **** up their *** ****.

* The binary should be located under the project directory. Could not make the GUI recognize any build variables or linked resource paths to specify the binary to debug.

Anyway this is definitely a progress.

Thanks!

-- pa

Update:

Re. point #2 about existing makefile projects: there still is a way to salvage them.

Create a new dummy makefile project in CubeIDE and specify the correct MCU as explained above in Mattias' post.

Build the dummy project to produce an .elf file, create a debug launch config for it.

Then transplant the real .elf created by the real makefile onto the dummy project:

On the Startup tab, add the real elf. Specify for it download and load symbols. but not build. The green arrow should point to this real file.

For the dummy .elf, uncheck load and load symbols.

Now, you should be able to debug it.

So I installed Cube 1.6.0, used CMake to create a makefile project, then proceeded with the steps @mattias norlander​ gave.

This does give me a project that I can build from the CubeIDE, and I can create a debug config and start a debug session.

But the debugger doesn't find the source files, and adding things to the 'Source' tab doesn't help.

Even if I put in a fully-specified file + path name, the debugger will say it can't find the file - with that exact same path + name!

Possibly related to this, stepping seems flaky - I guess the source file I think I'm looking at isn't what/where the debugger thinks it's looking?

I tried adding a 'Source Folder' to the project:

0693W000008wdz6QAA.pngNote the '>' indicating that it can be expanded & has stuff beneath.

But, after I added the Debug Configuration, the 'Source Folder' became empty:

0693W000008wdzQQAQ.pngNote how the '>' has gone - there is now nothing to expand!

So, instead, I tried a just a 'Folder' - not a 'Source Folder' - and used the 'Advanced' options to point to the source files location:

0693W000008we0OQAQ.pngWhich gives

0693W000008we3SQAQ.pngand I could add that as a 'Workspace Folder' to the Debug Config:

0693W000008we4GQAQ.png 

and that does seem to enable the debugger to find the source files.

Perhaps someone could explain the difference between a 'Folder' and a 'Source Folder' ?

perhaps I should add that the structure of the OSS-7 tree is like this:

OSS7 ---+--- cubewsp                    << folder for the CubeIDE Workspace
        |
        +--- src ----+--- stack ...     << the stack source tree
                     |
                     +--- build         << the makefiles created by CMake

so the source files are not "beneath" the makefiles - they are in a tree alongside them