Workspace chaos!

I have been using PlatformIO for a few days so far without too much difficulty. But I had imported an Arduino sketch and I noticed that the file in the src folder main.ino was being updated to .cpp and then disappearing. So I changed it to .cpp in my windows directory and then the fun started. Since then, the files won’t compile, and when I try to compile a specific file, a different project, which I built from scratch in PIO, gets compiled instead. Obviously I have messed up the file structure somehow. I uninstalled PIO and VS and then reinstalled, but the issue persists. Header files can’t be found and the incorrect project gets built. How can I completely start again? I have read through various related topics, but there are far too numerous suggested fixed, most of which are beyond my comprehension. I just want a clean start!

How do you compile one specifc file? Or do you mean the whole PlatformIO project?

What extensions in VSCode have you installed? “C/C++” by austin, by chance?

Hi Max,
I am just using 3 extensions C/C++; Live Server and PlatformIO.
When I mean compile, I just open the .cpp file in src and then click on the compile icon on the footer toolbar. But the intellisence doesn’t recognize the header files, in some projects not even arduino.h.
Thank you for your help and apologies for my lack of correct terminology. - Paul

I think I might know what’s happened here.

You renamed the *.ino file to *.cpp in the imported sketch folder and everything stopped compiling?

If so, add this line to the top of the file formerly known as *.ino:

#include "Arduino.h"

The letter case is significant by the way, upper case ‘A’.

Do a “clean” – click the dustbin/trashcan icon in the toolbar at the bottom, then do a normal build and it should work.

The problem is down to you renaming the file. With *.ino, PlatformIo – somehow – compiles in the same way as the Arduino IDE. After renaming to *.cpp it compiles as a plain C++ file, so it (the C++ compiler) has no idea what a pinMode() function is, for example. Adding in the Arduino.h file informs the compiler about these things in use in the Arduino “Language”.

I wrote a small tutorial on importing and converting a multi-ino Arduin Sketch to C++ which might be of interest/use in attempting to explain what goes on?

HTH

Cheers,
Norm.

1 Like

Hi Norm, in fact the main.cpp already had the #include “Arduino.h”, as it was one of the first things I understood when migrating from Arduino. What really puzzled me is seeing the compiler compiling a different project than the one I had open. EG So I have 5 projects in my workspace. I am working on main.cpp in Project 5, yet Project 4 gets compiled… I think I am confusing the open tasks (a the bottom of the window) with the projects in my workspace. I can’t seem to reconcile what is happening.
Meanwhile I have opened a new PIO project and copied the code into the blank main.cpp file and the correct project gets compiled and the headers are being recognized. So I will persevere with this route (only 21 errors found!!) Thank you for your assistance, Paul

1 Like

It might be safer to use the more explicit PlatformIO side bar -> project tasks -> Default (or your target environment) -> Build instead of the build button in the toolbar. Does that change anything?

Also, doing a project tasks -> Miscellaneous -> Rebuild IntelliSense might help.

For some strange reason, that option does not appear for me.
I just see under Miscellaneous

  • PlatformIO Core CLI
  • Clone Git Project
  • New Terminal
  • Upgrade PlatformIO Core

Do I need somehow to install intellisence (even though it seems to be throwing up errors)?

You’re looking in the Quick Access window, not the project tasks

Thank you. Yes I have now found it and I performed the rebuild. While I was there I tried “update all” and got this warning, is this significant?
Updating platformio/contrib-pysite 2.37.191020 @ ~2.37.0 [Incompatible 2.39.201019]

No.

1 Like

OK, I seem to be going round in circles. I have tried removing all the projects and reimporting them again, but I still end up with compiling just one project, when I am working on a different project. Whether I use the menu on the LHS or the toolbar at the bottom, same result. I open main.cpp on Project 1 and build, but the system builds Project 3.
Furthermore, Project Tasks has gone missing and only Quick Access is visible.
When I reimport the projects, none of the headers are recognized:-


If I completely remove VS and PlatformIO and make a fresh install, will this solve my messed up install?

When you import the sketches, how are you doing it? From the PlatformIO Home page?

If so, they will be imported into separate folders in your default projects location, on Windows this is, if I remember correctly, c:\users\YOUR-NAME\documents\platformio\projects.

After the import, the VSCode editor will open the newly imported project’s folder.

I’m wondering why/how you appear to have all your imported projects open at the same time?

Cheers,
Norm.

I have used the PlaformIO home page and selected the master folder, which I have called Projects, which contains the various projects.

workspace

When I try to reopen a project individually on the home page, it creates a duplicate, see Get Time marked with red x.
The earlier issue of the Project Tasks being missing, resolved itself, when I closed VS and re-opened it.

Why can I not rename the un-titled workspace? How does this differ from the main directory “Projects” underneath?

I think I have a very fragile installation and would like to know how I can completely uninstall and start afresh. Or is there a more obvious solution? Thank you for your continued assistance!

OK - I think I now realise what I was doing wrong. When I opened the projects, I selected the higher level directory, “Project” which opened all of the sub directories at once. I have now removed these and reinstalled each project individually, and now the header files are being recognized. It also explains why I thought the compiler was compiling the wrong project, as it was deferring to the projects which were opened individually instead of the projects within the project folder. Problem solved, I think (for now!) Thank you for your patience.

That’s what I thought might have been happening. Glad you got it sorted out.

I usually open my projects with File->Open Folder, then navigate to the folder holding the project I’m interested in, rather than using the “home” page.

Many ways to skin the proverbial cat. :wink:

Cheers,
Norm.

Thanks Norm for your perseverance and assistance.

No doubt I will have many more learning issues, but for now I reckon this question is closed, All the best, Paul

1 Like

No problem, ask away.

Cheers,
Norm.