arduino-mk: __bad_interrupt ... undefined reference to `main'

Still struggling with the command line version ("arduino-mk" from the Ubuntu repository).

My last problem ("EEPROM.h:25:7: error: expected ‘=’") was solved with the help of PaulS (renaming extensions from .c to .cpp).

Now all my files compiled, but a linker error occurs:

frank@office ~/ActDir $ make
cat build-cli/button.d build-cli/camBoard.d build-cli/clock.d build-cli/host.d build-cli/main.d build-cli/state.d > build-cli/depends.mk
/usr/bin/avr-gcc -mmcu=atmega328p -Wl,--gc-sections -Os -o build-cli/Source.elf build-cli/button.o build-cli/camBoard.o build-cli/clock.o build-cli/host.o build-cli/main.o build-cli/state.o build-cli/libcore.a  -lc -lm
/usr/lib/gcc/avr/4.5.3/../../../avr/lib/avr5/crtm328p.o: In function `__bad_interrupt':
../../../../crt1/gcrt1.S:195: undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [build-cli/Source.elf] Error 1

My code is pure C contained in a few .cpp and .h files. The main file is named 'main.ino', renaming it to 'main.cpp' changed nothing.

My Makefile is

frank@office ~/ActDir $ cat Makefile
ARDUINO_DIR = /usr/share/arduino
BOARD_TAG    = atmega328
AVR_TOOLS_PATH	= /usr/bin
AVRDUDE_CONF	= /etc/avrdude.conf
ARDUINO_PORT = /dev/ttyUSB0
ARDUINO_LIBS = EEPROM
include /usr/share/arduino/Arduino.mk

Environment:

frank@office ~/ActDir $ cat ~/.bashrc
# environment variables for arduino-mk
export ARDUINO_DIR=/usr/share/arduino
export ARDMK_DIR=/usr/share/arduino
export ARDMK_PATH=/usr/bin
export AVR_TOOLS_DIR=/usr

Any hint?

Any hint?

Post your sketch.

Read this before posting a programming question

How to use this forum

PaulS:

Any hint?

Post your sketch.

I didn't want to bother you with all my source code because I guessed the problem was in the Makefile or configuration.
The whole code exceeds the allowed length, so I add only the main program. I tried to attach a tarball with the complete source code, but its size is beyond limit.
Tell me whatever you find necessary and I will post it.

main.cpp:

/*******************************************************************
	Main program of firmware timeShotUSB for Arduino
*******************************************************************/

#include "camBoard.h"
#include "config.h"
#include "clock.h"
#include "button.h"
#include "host.h"
#include "state.h"

//#define DEBUG_ON

Timer	tButton, tHost, tState;
Button	button;
Host	host;
State	state;


/*	M a i n :   s e t u p   a n d   l o o p
	=======================================
*/


void setup()
{
  // debugging
  #ifdef DEBUG_ON
    Serial.begin(9600);
    Serial.println("debug on");
  #endif

  // initialize modules and objects
  HWInit();			// hardware
  Clock_Init();			// clock and timer functions
  Button_Init (&button);	// button (input)
  Host_Init (&host);		// communication module
  State_Init (&state);		// state machine

  // initialize timers
  Clock_TimerInit (&tButton, T_BUTTON);// button timer
  Clock_TimerInit (&tHost, T_HOST);	// host timer
  Clock_TimerInit (&tState, T_STATE);	// state machine timer
} // setup



void loop()
{
  Clock_Clock();	// get actual time internally once per it.

  if (Clock_Tick(&tButton)) Button_Read (&button);
  if (Clock_Tick(&tHost)) Host_Comm (&host);
  if (Clock_Tick(&tState)) State_Process (&button, &host, &state);
  // Led_display is so simple that it is done by State_Process()
} // loop

The whole code exceeds the allowed length

As far as I'm aware, there is no limit on attachments

Not sure about the reason of your response.

Case it is because I didn't post any code in my posting: I think the people who respond here do it as a volunteer, they spend their time to help, so if one posts a question one should do everything to reduce this time. And selecting information, posting only the relevant part is one means to that end.

If the customs on this list are to post every bit of information right in the beginning, tell me and I will follow.

AWOL:

The whole code exceeds the allowed length

As far as I'm aware, there is no limit on attachments

My error: There is a limit, 4096 KB, but not 4.096 KB as I thought first.

I am attaching the complete source now.

src.tar.bz2 (4.4 KB)

So, the IDE is not involved in the build process, right? So, the IDE isn't adding function prototypes, include files, a main() function, and a call to init().

Who's responsibility do you suppose that is, then?

hreba:
Not sure about the reason of your response.

Case it is because I didn't post any code in my posting: I think the people who respond here do it as a volunteer, they spend their time to help, so if one posts a question one should do everything to reduce this time.

Saying you have a compile problem, without showing the code, is like telling the doctor your child is sick, without bringing the child with you to "reduce time" the doctor has to spend. Actually it increases it, don't you see? We have wasted a few posts now asking for the problem code.

There are a couple of "stickies" at the head of the forum sections, I posted links to both of them. They ask for you to post code for programming questions, and show how to make attachments.

So if you really want to save the volunteers' time you read those first.

And selecting information, posting only the relevant part is one means to that end.

I have lost track of the number of times that people post five or six lines of code which they have carefully "selected" to be the problem part, when in fact the problem is elsewhere.

PaulS:
So, the IDE is not involved in the build process, right? So, the IDE isn't adding function prototypes, include files, a main() function, and a call to init().

Who's responsibility do you suppose that is, then?

Ok, so once more the problem is the command line tool chain. I simply followed its documentation and examples and hoped it would work. But it doesn't, so far. To answer your question directly, I thought it was the responsibility of the Makefile and the references therein (Arduino.mk) to include and reference eveything.

Now it seems to me that I have to dig into the details about how to write a Makefile which works. And I wonder what is the use of that package arduino-mk then.

Ok, so once more the problem is the command line tool chain. I simply followed its documentation and examples and hoped it would work. But it doesn't, so far. To answer your question directly, I thought it was the responsibility of the Makefile and the references therein (Arduino.mk) to include and reference eveything.

There is nothing wrong with the tool chain.

Compile your code using the IDE. Use File + Preferences to turn on verbose mode. Look at the cpp file that gets created from your sketch, BY THE IDE.

If you want to bypass the IDE, YOU must do all the stuff that the IDE does to the sketch to make a cpp file.

I know, this is an old question but it was not solved here and may be it will be helpful for others. I got the similar problem when started to use arduino-mk toolchain.
The problem is that your project contains main.cpp file. When compiling, it overwrites arduino's main.o file, and thus, there is no reference to the main() function.

i just had the same problem and i came across your post

my code was basically the following snippet

#ifdef RUN_TEST_MAIN

void abcabc(void)
{
........
}

int main(void)
{
.......
}

#endif

the error shows up if RUN_TEST_MAIN is not defined, because main() never gets compiled
(it was to be defined in .h file)

maybe your issue is similar, or you may have two main() procedures and one trashes the other