carduinoavrarduino-ide

AVR C code gets compiled successfully but in arduino ide it gives me error of missing functions


so i'm trying to call a c function in a c file in arduino uno.

using the gcc-avr command it gets compiled successfully:

sudo avr-gcc -Os -DF_CPU=16000000UL -mmcu=atmega328p -c -o nrf nrf.c

but on arduino ide, it gives me error of missing functions that the nrf.c is calling which exist in other c files. so how to fix it?

.ino file

#include "nrf.c"

extern "C" // these functions does not exist in c file they are in a .s file
{
    void init_serial();
    void print_msg();
    void light();
}
//----------------------------------------------------
void setup()
{
}

void loop(){
    nrf_start1();
    light();
}

this is the arduino ide's output:

/tmp/arduino/sketches/8589FEB308F7EAA6CFEF4682C1500C77/sketch/sketch_jul11a.ino.cpp.o (symbol from plugin): In function `nrf_start1()':
(.text+0x0): multiple definition of `__vector_1'
/tmp/arduino/sketches/8589FEB308F7EAA6CFEF4682C1500C77/sketch/nrf.c.o (symbol from plugin):(.text+0x0): first defined here
/tmp/arduino/sketches/8589FEB308F7EAA6CFEF4682C1500C77/sketch/sketch_jul11a.ino.cpp.o (symbol from plugin): In function `nrf_start1()':
(.text+0x0): multiple definition of `message_received'
/tmp/arduino/sketches/8589FEB308F7EAA6CFEF4682C1500C77/sketch/nrf.c.o (symbol from plugin):(.text+0x0): first defined here
/tmp/arduino/sketches/8589FEB308F7EAA6CFEF4682C1500C77/sketch/sketch_jul11a.ino.cpp.o (symbol from plugin): In function `nrf_start1()':
(.text+0x0): multiple definition of `status'

i tried to call the compiled one using extern c but it did not work


Solution

    1. Don't (ever) #include .c files. That's wrong in 99.9% of cases
    2. You need to tell the Arduino IDE that your sketch contains more files than the single .ino. You do that by copying your "nrf.c" file to where your sketch lives and use "Sketch"->"Add File...". The Arduino IDE should now know that your Sketch consists of multiple files and generate appropriate linker commands. From your question, it is not clear to me if you did that already or not.
    3. If you happen to have an additional ".S" file (not entirely clear from your question), do the same with that (but note, on some OSs, the IDE wants to see such files with an explicit upper-case "S" to recognize them as assembly source.