I started some days ago with using Arduino IDE V2.3.2 but I think it needs to be cooking a little more, at least
I had some simple sketches running in IDE V2.3.2 and stored on my NAS-drive at this path: X:\2 - Måneds\02 ArduinoProjects … with spaces as a part of the path - it has worked fine for years and I will NOT change that
I installed PlatformIO and opened one of my simple sketches - a main program with a header file and a cpp file stored in my LIBRARIES folder on my NAS-drive.
The sketch worked fine in the Arduino IDE but will NOT compile i PlatformIO !
The ‘Fix-bolb’ is telling me to add my NAS-path to the ‘includePath’ - but how should it be done - I know WHERE but can’t figure out the ‘syntax’ - something like:
${X:\2 - Måneds\02 ArduinoProjects}/** as a new line in the field.
But it still don’t compile - same error messages !
References to all libraries used in the project, should be in platformio.ini file, keeping the libraries in the global libraries folder is not good idea. Use library manager.
Why not just do what PFIO tells in the ‘fix’:
"#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit … "
My problem is I don’t know how the new line should look like in the ‘includePath’ field.
X:\2 - Måneds\02 ArduinoProjects\BlinkLED_OOP>pio system info
-------------------------- ------------------------------------------------------
PlatformIO Core 6.1.13
Python 3.11.7-final.0
System Type windows_amd64
Platform Windows-10
File System Encoding utf-8
Locale Encoding cp1252
PlatformIO Core Directory C:\Users\kelds\.platformio
PlatformIO Core Executable C:\Users\kelds\.platformio\penv\Scripts\platformio.exe
Python Executable C:\Users\kelds\.platformio\penv\Scripts\python.exe
Global Libraries 0
Development Platforms 1
Tools & Toolchains 5
-------------------------- ------------------------------------------------------
First let me say - I found out how to set up my main.cpp and the included files in the structure and I can now compile the main.cpp.
I then used the yellow bolb to do the ‘quick fix’ to change the ‘includePath’ - some new lines with paths was added - but unfortunaly I did something so my window in the button of the screen do NOT show errors any more under the "Problems’ - how can I get them back because - I can see there is STILL some errors when I compile:
C:\Users\kelds\AppData\Local\Temp\ccxTIpok.ltrans0.ltrans.o: In function `main':
<artificial>:(.text.startup+0x8a): undefined reference to `EnLED::init()'
<artificial>:(.text.startup+0x96): undefined reference to `EnLED::on()'
<artificial>:(.text.startup+0xaa): undefined reference to `EnLED::off()'
C:\Users\kelds\AppData\Local\Temp\ccxTIpok.ltrans0.ltrans.o: In function `_GLOBAL__sub_I_minLED':
<artificial>:(.text.startup+0x13c): undefined reference to `EnLED::EnLED(unsigned char, String)'
collect2.exe: error: ld returned 1 exit status
Hope you can help - I’m so sick and tires of that old Arduino version 1.X IDE and the version 2.X do need a little more coocking - I think !
I copied some project to at folder names “PlatformIO_Project” in the root of the NAS-drive and I can open the project from earlier in the thread - but I think I have the same problem - here is the compiling result:
Processing uno (platform: atmelavr; board: uno; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: Atmel AVR (5.0.0) > Arduino Uno
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash
DEBUG: Current (avr-stub) External (avr-stub, simavr)
PACKAGES:
framework-arduino-avr @ 5.2.0
toolchain-atmelavr @ 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies…
No dependencies
Building in release mode
Compiling .pio\build\uno\src\main.cpp.o
Archiving .pio\build\uno\libFrameworkArduinoVariant.a
Compiling .pio\build\uno\FrameworkArduino\CDC.cpp.o
Compiling .pio\build\uno\FrameworkArduino\HardwareSerial.cpp.o
Compiling .pio\build\uno\FrameworkArduino\HardwareSerial0.cpp.o
Compiling .pio\build\uno\FrameworkArduino\HardwareSerial1.cpp.o
Compiling .pio\build\uno\FrameworkArduino\HardwareSerial2.cpp.o
Compiling .pio\build\uno\FrameworkArduino\HardwareSerial3.cpp.o
Compiling .pio\build\uno\FrameworkArduino\IPAddress.cpp.o
Compiling .pio\build\uno\FrameworkArduino\PluggableUSB.cpp.o
Compiling .pio\build\uno\FrameworkArduino\Print.cpp.o
Compiling .pio\build\uno\FrameworkArduino\Stream.cpp.o
Compiling .pio\build\uno\FrameworkArduino\Tone.cpp.o
src\main.cpp:17:14: error: expected constructor, destructor, or type conversion before ‘(’ token
EnLED::minLED(LED_PIN, “Red”);
^
src\main.cpp: In function ‘void setup()’:
src\main.cpp:21:3: error: ‘minLED’ was not declared in this scope
minLED.init();
^~~~~~
src\main.cpp:21:3: note: suggested alternative: ‘EnLED’
minLED.init();
^~~~~~
EnLED
src\main.cpp: In function ‘void loop()’:
src\main.cpp:26:3: error: ‘minLED’ was not declared in this scope
minLED.on(); // turn the LED on (HIGH is the voltage level)
^~~~~~
src\main.cpp:26:3: note: suggested alternative: ‘EnLED’
minLED.on(); // turn the LED on (HIGH is the voltage level)
^~~~~~
EnLED
*** [.pio\build\uno\src\main.cpp.o] Error 1
====================================================================== [FAILED] Took 5.61 seconds ===
Be aware that
I uninstalled VSCode and reinstalled it and installed PlatformIO again, so I think the ‘quick-fixes’ from before is illiminated.
I have files main.cpp in scr-folder and EnLED.h and EnLED.cpp in the includefolder of the project.
The README.md located inside the include folder clearly says:
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in src folder
by including it, with the C preprocessing directive `#include’.
Moving the EnLED.cpp into the src folder should fix this issue.
I’ve now started all over by creating a new project in PlatformIO.
In the “src” I then - one by one - copied from the old ArduinoIDE the 3 files I had over there and pasted them in 3 files here in the “src”:
“main.cpp”, “EnLED.h” and “EnLED.cpp”
Compiled it without any errors and it run nicely on the board !!!
I now MOVED the “EnLED.h” to the “include”-folder and compiled again - it STILL works nicely - I didn’t change anything at all.
If I MOVES the “EnLED.cpp” file from “src” to the “include” folder it WONT work !
Should I then conclude that in PlatformIO it’s NOT good practice to split an object into a sort of ‘interface’ (the xxx.h file) and a cpp-file with ALL the code details ?
I think it is a mess to have the code details file ( the EnLED.cpp) in the same folder as the main.cpp.
… or do I misunderstand something here - please, teach me “the best practice” !
Iss that a good practice if you want to make object for one or more libraries in the longer run - these objects shold be accesable from other projects too, I think
For libraries I recommend to use the lib folder.
Create a sub folder for each library. Put the code files (.h & .cpp) in another subfolder “src”. Add a library manifest “library.json” at the same level as the librarys “src” folder. For details see