Not able to compile multiple files in VScode

Hello,
Hope you guys are doing fine.I am new to visual studio code and I am working with my project but now I am facing problem when combining all the header files and could not able to get the program compile. I searched a lot about it but all in vein. Here is the error.

> Executing task: platformio run <

Processing uno (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 2.2.0 > Arduino Uno
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash
DEBUG: Current (simavr) On-board (simavr)
PACKAGES: 
 - framework-arduino-avr 5.0.0 
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 6 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <SoftwareSerial> 1.0
Building in release mode
Compiling .pio/build/uno/src/main.cpp.o
Linking .pio/build/uno/firmware.elf
.pio/build/uno/src/DriveWheel.cpp.o (symbol from plugin): In function `Roomba':
(.text+0x0): multiple definition of `Roomba'
.pio/build/uno/src/DriveStop.cpp.o (symbol from plugin):(.text+0x0): first defined here
.pio/build/uno/src/Rdistance.cpp.o (symbol from plugin): In function `Roomba':
(.text+0x0): multiple definition of `Roomba'
.pio/build/uno/src/DriveStop.cpp.o (symbol from plugin):(.text+0x0): first defined here
.pio/build/uno/src/RoombaStart.cpp.o (symbol from plugin): In function `Roomba':
(.text+0x0): multiple definition of `Roomba'
.pio/build/uno/src/DriveStop.cpp.o (symbol from plugin):(.text+0x0): first defined here
.pio/build/uno/src/TurnCCW.cpp.o (symbol from plugin): In function `Roomba':
(.text+0x0): multiple definition of `Roomba'
.pio/build/uno/src/DriveStop.cpp.o (symbol from plugin):(.text+0x0): first defined here
.pio/build/uno/src/TurnCCW2.cpp.o (symbol from plugin): In function `Roomba':
(.text+0x0): multiple definition of `Roomba'
.pio/build/uno/src/DriveStop.cpp.o (symbol from plugin):(.text+0x0): first defined here
.pio/build/uno/src/TurnCW.cpp.o (symbol from plugin): In function `Roomba':
(.text+0x0): multiple definition of `Roomba'
.pio/build/uno/src/DriveStop.cpp.o (symbol from plugin):(.text+0x0): first defined here
.pio/build/uno/src/UltraDist.cpp.o (symbol from plugin): In function `Roomba':
(.text+0x0): multiple definition of `Roomba'
.pio/build/uno/src/DriveStop.cpp.o (symbol from plugin):(.text+0x0): first defined here
.pio/build/uno/src/drive.cpp.o (symbol from plugin): In function `Roomba':
(.text+0x0): multiple definition of `Roomba'
.pio/build/uno/src/DriveStop.cpp.o (symbol from plugin):(.text+0x0): first defined here
.pio/build/uno/src/main.cpp.o (symbol from plugin): In function `Roomba':
(.text+0x0): multiple definition of `Roomba'
.pio/build/uno/src/DriveStop.cpp.o (symbol from plugin):(.text+0x0): first defined here
/tmp/cclRyuyU.ltrans0.ltrans.o: In function `__static_initialization_and_destruction_0(int, int) [clone .constprop.10]':
<artificial>:(.text.startup+0xe): undefined reference to `txPin'
<artificial>:(.text.startup+0x12): undefined reference to `txPin'
<artificial>:(.text.startup+0x16): undefined reference to `rxPin'
<artificial>:(.text.startup+0x1a): undefined reference to `rxPin'
collect2: error: ld returned 1 exit status
*** [.pio/build/uno/firmware.elf] Error 1
========================================================= [FAILED] Took 1.22 seconds =========================================================
The terminal process "platformio 'run'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

My code main file is…
main.cpp

#include <Arduino.h>
#include<Roombawake.h>
#include<RoombaStart.h>
#include<TurnCW.h>
#include<TurnCCW.h>
#include<drive.h>
#include<tic.h>
#include<TurnCCW2.h>
#include<Rdistance.h>
#include<DriveStop.h>
#include<SoftwareSerial.h>


void setup() {

}

void loop() {

}

Also attach the header files

drive.cpp (316 Bytes)

drive.h (130 Bytes)

DriveStop.cpp (61 Bytes)

DriveStop.h (82 Bytes)

DriveWheel.cpp (286 Bytes)

DriveWheel.h (101 Bytes)

EEPROM.h (5.33 KB)

main.cpp (270 Bytes)

Rdistance.cpp (512 Bytes)

Rdistance.h (140 Bytes)

RoombaStart.cpp (163 Bytes)

RoombaStart.h (202 Bytes)

Roombawake.cpp (238 Bytes)

Roombawake.h (103 Bytes)

tic.cpp (918 Bytes)

tic.h (116 Bytes)

TurnCCW.cpp (691 Bytes)

TurnCCW.h (303 Bytes)

TurnCCW2.cpp (220 Bytes)

TurnCCW2.h (140 Bytes)

Don't define variables in header files, only declare them. The Roomba variable in RoombaStart.h should be extern. When you declare a variable as extern, you have to provide a definition somewhere else, in an implementation file. This is the problem with the "undefined reference to `rxPin'", you declared the variable, but never defined it (or you didn't compile the file it's compiled in).

To debug these kinds of errors, you need to have a basic understanding of how the C++ compilation process works. For example= c++ - How does the compilation/linking process work? - Stack Overflow. You also have to understand the difference between declarations and definitions.

Pieter

Hi PieterP,
Thank you so much for the answer and the guide lines...
It worked. :slight_smile: