Libraries are NOT fool proof, actually a huge time sink

I’d love help with the program, but please help me understand how I raise these errors.

They seem very foundational. Like, I feel like I really need to understand this.

It seems like I have to add the same library over and over.

Adafruit_MPL3115A2, for example. I’ve had to re-add it every time I use the sensor in a new file.

Please read the error a bit closer - it says In function 'main' - not that main is missing or undefined. So do NOT declare it in your source. i.e. REMOVE int main() {} as shown at line 22 of that screenshot.

When you press Build, files in \src (i.e. the src directory of your project) are build. When you press Test, files in \test (the test directory of your project) are built. Do you have a main.cpp in \test that defines what the setup and loop functions do?

Do NOT use/press Test unless you intend to do Unit Testing (meaning you have written test code to verify if given valid input, your code works, or given invalid input, your code appropriately handles it). It is not the ‘verify/compile’ button, like on the Arduino IDE. Use the Build button to ‘test’ if code compiles.

it says ‘undefined reference to loop’.

I need to understand why it says that, when loop is really here.

If you add a main() to an Arduino sketch, you are telling the Arduino IDE that I am in command, I know what I’m doing, do not do any of the Arduino “Language” hand holding or startup initialisation stuff like enabling global interrupts, Timer/Counter 0 Overflow interrupt for millis() etc

You’re code above has defined an empty main() so that will execute and finish at runtime, almost immediately. Nothing else gets called. Assuming it compiles!

EDIT: Removed incorrect info. I was confused by the non-formatted code and missed an opening brace.

It’s easier on the eye if you wrap code blocks in 4 back ticks above and below the code block, that preserves indentation etc, like this:

void setup() {
    Serial.begin(9600);
    Serial.println("Hello Norm's strange world!");
    // Etc.
}

void loop() {
    // Do loopy stuff here.
}

You can inline bits of code with a single backtick like Serial.print(1234, HEX);, for example.

Anyway, I got distracted. I think if you remove main(){} and, assuming I’m figuring out the braces correctly, your errors should vanish.

Good luck.

By the way, I think your libraries are being installed on a per-project basis. Add the -g AKA --global flag to the platformio lib install ... command to install the library once only, globally. Then use lib_deps, in your platformio.ini file, when you want to use the library.

HTH

Cheers,
Norm.

Trying to put it simply, if you are using PlatfomIO simply to replace the Arduino IDE, you only need write the setup() and loop() functions, plus any support functions you decide to write. (Plus adding #include <Arduino.h>" at the start of course.

Do not include a main() function in your code.

Cheers,
Norm.

1 Like

Thank you, but the main() was added as a shot in the dark. It actually sat quietly and did nothing.