Issue with library under MacOs VSCode when using multiple configuration file

Dear,
I’m coding a multiple configuration files for Arduino dev. When building, I’ve got many error concerning libraries…
Please find hereafter the .ini file and my source file.

Thanks a lot for your support.

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env]
platform = atmelavr
board = uno
framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries
lib_ldf_mode = chain+

[env:projet2]
platform = atmelavr
board = uno
framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries
build_src_filter = +</Users/florenttainturier/Fablab-Escape/fablabescape/Fabrication/EscapeMain-TestServo/src/projet2>

[env:projet1]
platform = atmelavr
board = uno
framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries
build_src_filter = +</Users/florenttainturier/Fablab-Escape/fablabescape/Fabrication/EscapeMain-TestServo/src/projet1>

And one of my example test :slight_smile:

#include <Wire.h>

void setup() {
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onRequest(requestEvent); // register event
}

void loop() {
  delay(100);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
  Wire.write("hello "); // respond with message of 6 bytes
  // as expected by master
}

My error messages

 *  Executing task in folder EscapeMain-TestServo: platformio run --environment projet1 

Processing projet1 (platform: atmelavr; board: uno; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
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 -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain+, Compatibility ~ soft
Found 25 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Wire @ 1.0
Building in release mode
Compiling .pio/build/projet1/src/projet1/sender.c.o
Archiving .pio/build/projet1/libd66/libWire.a
Compiling .pio/build/projet1/FrameworkArduino/HardwareSerial2.cpp.o
In file included from /Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Print.h:27:0,
                 from /Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Stream.h:26,
                 from /Users/florenttainturier/.platformio/packages/framework-arduino-avr/libraries/Wire/src/Wire.h:27,
                 from src/projet1/sender.c:1:
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Printable.h:25:1: error: unknown type name 'class'; did you mean 'labs'?
 class Print;
 ^~~~~
 labs
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Printable.h:33:1: error: unknown type name 'class'; did you mean 'labs'?
 class Printable
 ^~~~~
 labs
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Printable.h:34:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
In file included from /Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Stream.h:26:0,
                 from /Users/florenttainturier/.platformio/packages/framework-arduino-avr/libraries/Wire/src/Wire.h:27,
                 from src/projet1/sender.c:1:
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Print.h:37:1: error: unknown type name 'class'; did you mean 'labs'?
 class Print
 ^~~~~
 labs
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Print.h:38:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
In file included from /Users/florenttainturier/.platformio/packages/framework-arduino-avr/libraries/Wire/src/Wire.h:27:0,
                 from src/projet1/sender.c:1:
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Stream.h:49:1: error: unknown type name 'class'; did you mean 'labs'?
 class Stream : public Print
 ^~~~~
 labs
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Stream.h:49:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
 class Stream : public Print
              ^
In file included from src/projet1/sender.c:1:0:
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/libraries/Wire/src/Wire.h:34:1: error: unknown type name 'class'; did you mean 'labs'?
 class TwoWire : public Stream
 ^~~~~
 labs
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/libraries/Wire/src/Wire.h:34:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
 class TwoWire : public Stream
               ^
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/libraries/Wire/src/Wire.h:86:8: error: unknown type name 'TwoWire'
 extern TwoWire Wire;
        ^~~~~~~
src/projet1/sender.c: In function 'setup':
src/projet1/sender.c:4:7: error: request for member 'begin' in something not a structure or union
   Wire.begin(8);                // join i2c bus with address #8
       ^
src/projet1/sender.c:5:7: error: request for member 'onRequest' in something not a structure or union
   Wire.onRequest(requestEvent); // register event
       ^
src/projet1/sender.c:5:18: error: 'requestEvent' undeclared (first use in this function)
   Wire.onRequest(requestEvent); // register event
                  ^~~~~~~~~~~~
src/projet1/sender.c:5:18: note: each undeclared identifier is reported only once for each function it appears in
src/projet1/sender.c: In function 'loop':
src/projet1/sender.c:9:3: warning: implicit declaration of function 'delay' [-Wimplicit-function-declaration]
   delay(100);
   ^~~~~
src/projet1/sender.c: In function 'requestEvent':
src/projet1/sender.c:15:7: error: request for member 'write' in something not a structure or union
   Wire.write("hello "); // respond with message of 6 bytes
       ^
Compiling .pio/build/projet1/FrameworkArduino/HardwareSerial3.cpp.o
*** [.pio/build/projet1/src/projet1/sender.c.o] Error 1
Indexing .pio/build/projet1/libd66/libWire.a
========================================================== [FAILED] Took 0.45 seconds ==========================================================

Environment    Status    Duration
-------------  --------  ------------
projet1        FAILED    00:00:00.448
==================================================== 1 failed, 0 succeeded in 00:00:00.448 ====================================================

 *  The terminal process "platformio 'run', '--environment', 'projet1'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

Does the issue also happens, if you remove this line from all environments in your platformio.ini ?

There are also two issues with this code.
You missed to include Arduino.h:

#include <Arduino.h>

You need to pre-declare requestEvent before you can use it in setup():

void requestEvent();

void setup() {
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onRequest(requestEvent); // register event
}

Here is the complete code:

#include <Arduino.h>
#include <Wire.h>

void requestEvent();

void setup() {
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onRequest(requestEvent); // register event
}

void loop() {
  delay(100);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
  Wire.write("hello "); // respond with message of 6 bytes
  // as expected by master
}

You can keep the platformio.ini much simpler:

[env]
platform = atmelavr
board = uno
framework = arduino

[env:project1]
build_src_filter = +<project1>

[env:project2]
build_src_filter = +<project2>

File and folder structure:

.
├── include
├── lib
├── src
│   ├── project1
│   │   └── main.cpp
│   └── project2
│       └── main.cpp
├── test
└── platformio.ini

Note: please try to avoid lib_extra_dirs = ~/Documents/Arduino/libraries
This leads to problems with a probability of 99.9%.

Use lib_deps for external libraries: lib_deps — PlatformIO latest documentation

Dear @sivar2311 , thanks for your advice. I will try next week the setup (I have no more access to my laboratory for few days).

Note : Previously , I was using the same code but without multiple configuration and I was able to build my code.

Dear @sivar2311 Finally I succeeded to test something before leaving. I have modify my code with your proposal (thank you much).

Unfortunately, here are my new errors :slight_smile:

Processing projet1 (platform: atmelavr; board: uno; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
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 -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Wire @ 1.0
Building in release mode
Compiling .pio/build/projet1/src/projet1/sender.c.o
Compiling .pio/build/projet1/libd66/Wire/Wire.cpp.o
Compiling .pio/build/projet1/libd66/Wire/utility/twi.c.o
Archiving .pio/build/projet1/libFrameworkArduinoVariant.a
Compiling .pio/build/projet1/FrameworkArduino/CDC.cpp.o
Compiling .pio/build/projet1/FrameworkArduino/HardwareSerial.cpp.o
Compiling .pio/build/projet1/FrameworkArduino/HardwareSerial0.cpp.o
In file included from /Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Print.h:27:0,
                 from /Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Stream.h:26,
                 from /Users/florenttainturier/.platformio/packages/framework-arduino-avr/libraries/Wire/src/Wire.h:27,
                 from src/projet1/sender.c:2:
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Printable.h:25:1: error: unknown type name 'class'; did you mean 'labs'?
 class Print;
 ^~~~~
 labs
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Printable.h:33:1: error: unknown type name 'class'; did you mean 'labs'?
 class Printable
 ^~~~~
 labs
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Printable.h:34:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
In file included from /Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Stream.h:26:0,
                 from /Users/florenttainturier/.platformio/packages/framework-arduino-avr/libraries/Wire/src/Wire.h:27,
                 from src/projet1/sender.c:2:
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Print.h:37:1: error: unknown type name 'class'; did you mean 'labs'?
 class Print
 ^~~~~
 labs
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Print.h:38:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
In file included from /Users/florenttainturier/.platformio/packages/framework-arduino-avr/libraries/Wire/src/Wire.h:27:0,
                 from src/projet1/sender.c:2:
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Stream.h:49:1: error: unknown type name 'class'; did you mean 'labs'?
 class Stream : public Print
 ^~~~~
 labs
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/cores/arduino/Stream.h:49:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
 class Stream : public Print
              ^
In file included from src/projet1/sender.c:2:0:
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/libraries/Wire/src/Wire.h:34:1: error: unknown type name 'class'; did you mean 'labs'?
 class TwoWire : public Stream
 ^~~~~
 labs
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/libraries/Wire/src/Wire.h:34:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
 class TwoWire : public Stream
               ^
/Users/florenttainturier/.platformio/packages/framework-arduino-avr/libraries/Wire/src/Wire.h:86:8: error: unknown type name 'TwoWire'
 extern TwoWire Wire;
        ^~~~~~~
src/projet1/sender.c: In function 'setup':
src/projet1/sender.c:7:7: error: request for member 'begin' in something not a structure or union
   Wire.begin(8);                // join i2c bus with address #8
       ^
src/projet1/sender.c:8:7: error: request for member 'onRequest' in something not a structure or union
   Wire.onRequest(requestEvent); // register event
       ^
src/projet1/sender.c: In function 'requestEvent':
src/projet1/sender.c:18:7: error: request for member 'write' in something not a structure or union
   Wire.write("hello "); // respond with message of 6 bytes
       ^
Compiling .pio/build/projet1/FrameworkArduino/HardwareSerial1.cpp.o
Compiling .pio/build/projet1/FrameworkArduino/HardwareSerial2.cpp.o
*** [.pio/build/projet1/src/projet1/sender.c.o] Error 1
Indexing .pio/build/projet1/libFrameworkArduinoVariant.a
================================================= [FAILED] Took 0.43 seconds =================================================

Environment    Status    Duration
-------------  --------  ------------
projet1        FAILED    00:00:00.432
============================================ 1 failed, 0 succeeded in 00:00:00.432 ============================================

 *  The terminal process "platformio 'run', '--environment', 'projet1'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

Can you share the complete project?
Upload on github or as zip via a file hoster.

Dear, please hereafter the complete doc.
Note : the original project is a fork and I am refactoring all the code. So sorry for the aspect of the repository.
https://gitlab.com/eclisia/fablabescape/-/tree/feature/I2Ctest/Fabrication/EscapeMain-TestServo?ref_type=heads

You are using the wrong file extention!

Rename your source files from .c to .cpp.