Multiple files project - #ifndef ignored

Dear all,

I’m trying to shift from Arduino IDER to PlatformIO (Visual Studio Code). I have projects with multiple “.ino” files and try to convert them. Unfortunately I’m unable to build the program. I read various posts but couldn’t find a suitable response to my problem.

A simplified version of the current setup has 4 files in /src folder as follows:
/src/main.cpp

#include <Arduino.h>
#include “00_main.h”

void setup() {
serial_setup();
fs_setup();
}

void loop() {
do_something();
}

00_main.h

#pragma once
#ifndef CONFIG_H
#define CONFIG_H

#message “Include configuration file”

#include <Arduino.h>

void serial_setup();

void fs_setup();
#endif

01_serial.cpp

#include <Arduino.h>
#include “00_main.h”

void serial_setup() {
Serial.begin(115200);
}

02_fs.cpp

#include <Arduino.h>
#include “00_main.h”

/***********************************************************************
Prepare filesystem
***********************************************************************/
void fs_setup() {
if (!FileFS.begin()) {
FileFS.format();
}

My platform.ini looks like this one:
[platformio]>

description = ESP based Influx logger for BYD Combo2
default_envs = ESP32

[env]
build_flags =
-D DEBUG_ESP_PORT=Serial
-D NDEBUG
lib_archive = no
lib_ldf_mode = chain
lib_compat_mode = strict
upload_speed = 921600
monitor_speed = 115200
monitor_filters =
esp8266_exception_decoder
default

[env:ESP32]
platform = espressif32
board = esp32dev
framework = arduino
board_build.mcu = esp32
board_build.f_cpu = 240000000L
board_build.partitions = huge_app.csv
board_build.filesystem = littlefs

Unfortunatley, the compilation is not possible. After some debugging I figured out that the 00_main.h is included by each .cpp file. The #ifndef at the beginning seems to be ignored.

In file included from src/02_fs.cpp:2:
src/00_main.h:5:4: error: invalid preprocessing directive #message
#message “Include configuration file”
^~~~~~~
In file included from src/01_serial.cpp:2:
src/00_main.h:5:4: error: invalid preprocessing directive #message
#message “Include configuration file”
^~~~~~~
In file included from src/main.cpp:17:
src/00_main.h:5:4: error: invalid preprocessing directive #message
#message “Include configuration file”

Most likely a very stupid mistake but I have no clue how to adress it. Any proposal from the community would be very appreciated.

The output is exactly as expected.

You have

And include it like

So, since Arduino.h does not defined CONFIG_H, at the point that 00_main.h is included, it will evaluate #ifndef CONFIG_H as being true and 1. define CONFIG_H for the current compilation unit and declare the functions. This happens for each compilation unit (src/02_fs.cpp, src/01_serial.cpp, src/main.cpp). This is exactly what the include guard in a header file should do: Declare the functions to a compilation unit if not already declared. The include guard prevents double inclusion by the same compilation unit, not “only one compilation unit can include this file globally”.

Another thing is that #message is not valid. Use #warning, for example, or #pragma message, as documented.

Thanks for the fast reply and confirming that the behavior is expected. Once formulating the issue I realize that at no point in the code / setup I specify, which is the “leading” cpp and which one are the “supporting” cpps. Arduino IDE is simpler/more tolerant and uses the file with the same name as the folder.

What is a good way to solve the situation inPlatformIO?
How do I need to link the various files to the same compilation unit?

In the meantime I tried to define a separate header file for each cpp file and include the individual header files (01_serial.h / 02_fs.h) ind the 00_main.h. But still no success…

P.S. I fixed the #message#warning statement.

What are the exact compilation errors you’re getting now? The only thing I can imagine is that you’re using e.g. FileFS.begin without the proper library header include it for it, whatever that might be.

No worries regarding the FS library. removed some code lines to simplify the post.

The (slightly confusing) build error output is shown below. I see a lot of multiple definition of statements all referring to the 00_main.h file.

Processing ESP32 (platform: espressif32; board: esp32dev; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: Espressif 32 (6.5.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:

  • framework-arduinoespressif32 @ 3.20014.231204 (2.0.14)
  • tool-esptoolpy @ 1.40501.0 (4.5.1)
  • toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
    LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
    LDF Modes: Finder ~ chain, Compatibility ~ strict
    Found 35 compatible libraries
    Scanning dependencies…
    Dependency Graph
    |-- FS @ 2.0.0
    |-- SPI @ 2.0.0
    |-- ArduinoJson @ 6.21.3
    |-- LittleFS @ 2.0.0
    |-- Wire @ 2.0.0
    Building in release mode
    Compiling .pio\build\ESP32\src\main.cpp.o
    Compiling .pio\build\ESP32\src\p\01_serial.cpp.o
    Compiling .pio\build\ESP32\src\p\02_fs.cpp.o
    In file included from src/main.cpp:17:
    src/p/00_main.h:5:4: warning: #warning “Include configuration file” [-Wcpp]
    #warning “Include configuration file”
    ^~~~~~~
    In file included from src/p/02_fs.cpp:2:
    src/p/00_main.h:5:4: warning: #warning “Include configuration file” [-Wcpp]
    #warning “Include configuration file”
    ^~~~~~~
    In file included from src/p/01_serial.cpp:2:
    src/p/00_main.h:5:4: warning: #warning “Include configuration file” [-Wcpp]
    #warning “Include configuration file”
    ^~~~~~~
    Linking .pio\build\ESP32\firmware.elf
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o: in function wdtSetup()': C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:35: multiple definition of wdtSetup()‘; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:35: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o: in function wdtReset()': C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:39: multiple definition of wdtReset()’; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:39: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o: in function espDelay(int)': C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:46: multiple definition of espDelay(int)‘; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:46: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o:C:\Users\user\OneDrive -
    Sciosense\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:22: multiple definition of LOCATION'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:22: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o:C:\Users\user\OneDrive - Sciosense\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:66: multiple definition of INFLUXDB_URL’; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:66: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o:C:\Users\user\OneDrive -
    Sciosense\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:67: multiple definition of INFLUXDB_TOKEN'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:67: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o:C:\Users\user\OneDrive - Sciosense\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:68: multiple definition of INFLUXDB_ORG’; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:68: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o:C:\Users\user\OneDrive -
    Sciosense\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:69: multiple definition of INFLUXDB_BUCKET'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:69: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o:C:\Users\user\OneDrive - Sciosense\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:29: multiple definition of systemDoc’; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:29: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o:C:\Users\user\OneDrive -
    Sciosense\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:31: multiple definition of configJSON'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:31: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o:C:\Users\user\OneDrive - Sciosense\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:32: multiple definition of configDoc’; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:32: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o:C:\Users\user\OneDrive -
    Sciosense\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:38: multiple definition of dummyJSON'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:38: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o:C:\Users\user\OneDrive - Sciosense\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:12: multiple definition of filesystem’; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:12: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o:C:\Users\user\OneDrive -
    Sciosense\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:65: multiple definition of OUT_DEBUG'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:65: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o:C:\Users\user\OneDrive - Sciosense\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:23: multiple definition of CYC_LOG’; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:23: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o:C:\Users\user\OneDrive -
    Sciosense\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:21: multiple definition of counterData'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:21: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o:C:\Users\user\OneDrive - Sciosense\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:19: multiple definition of currentTM’; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:19: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\01_serial.cpp.o:C:\Users\user\OneDrive -
    Sciosense\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:18: multiple definition of now'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:18: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o: in function wdtSetup()‘:
    C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:35: multiple definition of wdtSetup()'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:35: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o: in function wdtReset()’:
    C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:39: multiple definition of wdtReset()'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:39: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o: in function espDelay(int)‘:
    C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:46: multiple definition of espDelay(int)'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:46: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:65: multiple definition of OUT_DEBUG’; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:65: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:32: multiple definition of configDoc'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:32: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:31: multiple definition of configJSON’; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:31: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:22: multiple definition of LOCATION'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:22: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:23: multiple definition of CYC_LOG’; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:23: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:66: multiple definition of INFLUXDB_URL'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:66: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:67: multiple definition of INFLUXDB_TOKEN’; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:67: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:68: multiple definition of INFLUXDB_ORG'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:68: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:69: multiple definition of INFLUXDB_BUCKET’; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:69: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:29: multiple definition of systemDoc'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:29: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:38: multiple definition of dummyJSON’; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:38: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:12: multiple definition of filesystem'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/02_fs.h:12: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:21: multiple definition of counterData’; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:21: first defined here
    c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:19: multiple definition of currentTM'; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:19: first defined here c:/users/user/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\p\02_fs.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:18: multiple definition of now’; .pio\build\ESP32\src\main.cpp.o:C:\Users\user\OneDrive\PlatformIO\Projects\BYD_Combo2_Readout/src/p/00_main.h:18: first defined here
    collect2.exe: error: ld returned 1 exit status
    *** [.pio\build\ESP32\firmware.elf] Error 1
    ================================================================================================== [FAILED] Took 6.69 seconds ==================================================================================================
  • The terminal process “C:\Users\user.platformio\penv\Scripts\platformio.exe ‘run’, ‘–environment’, ‘ESP32’” terminated with exit code: 1.
  • Terminal will be reused by tasks, press any key to close it.

Oh yeah that doesn’t look good at all. You might get a naming clash because “CONFIG_H” might already be used elsewhere in the Arduino framework or compiler, that’s a too generic name. Let’s try and use just modern #pragma once statements.

Can you try this as the content for the 00_main.h file:

#pragma once

#warning "Include configuration file"

#include <Arduino.h>

void serial_setup();
void fs_setup();

Unfortunately the same result.

I did the #pragma change, a restart of Visual Studio Code and a “Full Clean”.
In addition I created for each cpp file a corresponding header file.

Now I have the structure:

In the terminal I see the various compiling statements and it looks like its compiling in separate elements and not combined

Compiling .pio\build\ESP32\src\01_serial.cpp.o
Compiling .pio\build\ESP32\src\02_fs.cpp.o
Compiling .pio\build\ESP32\src\main.cpp.o

That is correct and expected, each .cpp file will be turned into its own object file (.o) and the linker invocation at the very end will combine / link all object files to one executable (.elf) from which the binary image (.bin) is created.

The error logs also indicate some src/p/00_main.h files being present ebsides src/00_main.h etc.

Can you upload the current state of the project to Github or google drive or something? It’ll be easier to see the error.

I uploaded the code here chrfriese123/platformioTest (github.com)

No, you should never define (“implement”, with function code) a function in a header file. The header file should also declare the functions with its prototype (return type, name, function parameters) and have no implementation. Replace that with

void wdtSetup();
void wdtReset();
void espDelay(int ms);

then put the original function code (as quoted above) in one .cpp file (new or existing one).

This one is equally wrong. You can’t combine extern and setting an initial value. The header must only declare these variables as extern, type, name. Then in a .cpp file (new or existing), you give the variables their initial value.

    // in header file
    extern bool    OUT_DEBUG;
    extern String  INFLUXDB_URL;
    extern String  INFLUXDB_TOKEN;
    extern String  INFLUXDB_ORG;
    extern String  INFLUXDB_BUCKET;
    // in a .cpp file
    bool    OUT_DEBUG = false;        //serial sensor data output
    String  INFLUXDB_URL = "";
    String  INFLUXDB_TOKEN = "";
    String  INFLUXDB_ORG = "";
    String  INFLUXDB_BUCKET = "";

So it looks like I screwed up on multiple levels. After fixing the other files as well, compilation worked now.

Thanks for the support.