File name issue: main.ino doesn't compile but renamed file does

I have a fairly confusing problem. I have an Arduino sketch with four files-- main.ino, devices.h, devices.c, and the external library file digitalReadFast.h.

This sketch is part of a bigger software/hardware system I designed involving a Raspberry Pi. The goal is to package this software so that other people working in my lab can install everything from their own machines; all the end user should do is open the sketch in the Arduino IDE and hit upload. While packaging the Arduino software I ran into a rather curious problem.

I called the program main.ino and it compiled for some time using Stino/SB2 on a Ubuntu machine at the lab. Now at home, I want the same sketch to compile on my Mac-- however, I get the error message

main.cpp.o: In function `main':
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/main.cpp:11: undefined reference to `setup'
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/main.cpp:14: undefined reference to `loop'

Mind that this is the exact same sketch, just compiled on a different machine.

I decided to rename the sketch (save as>main_test in the Arduino IDE) and see if that compiled. Much to my surprise, it did! The files in the two different sketches are exactly the same, yet calling one version "main" prevents it from compiling.

It's not a huge issue, but it is quite annoying and perplexing. Does anyone know why this might be happening?

The repo linked to above includes the same code twice, with two different names. I figured it was too much code to embed in this post.

There is already a main.cpp file in the distribution which the IDE links in to give you the usual C "main" function. By naming your own file "main" you replace that (or it replaces yours, depending on the compile order).

You can see from the error message it is looking in "main.cpp.o" and since I think that was compiled later it would have overwritten your own "main.cpp.o", hence the missing functions.

yet calling one version "main" prevents it from compiling.

The IDE copies a file called main.cpp and your .ino files, and creates a file called main.cpp to be compiled. It skips the first step, copying the main.cpp file, when your sketch contains a main.ino file. That, of course, causes problems when function prototypes are not defined, like for setup() and loop(). It also causes problems when your sketch doesn't actually call init(), setup(), or loop() in an infinite loop.

The moral of the story? Don't call your sketch main.ino.

I assumed something like a module was called main as well but I was not really sure. Thanks.

It still bugs me that it compiled using Stino and ST2 on Linux (not sure which of those factors changes things), but not on my Mac.