Multiple Definitions

I’m having an issue when I try to compile code for an ESP8266 chip where I receive a multiple definitions error. However, I can’t see where/why the error is occurring as none of the functions in my files are defined twice.

Error:

sketch/Generic_RGBW_Light.ino.cpp.o: In function pwm_start': sketch/pwm.c:356: multiple definition of pwm_start’
sketch/pwm.c.o:sketch/pwm.c:356: first defined here
sketch/Generic_RGBW_Light.ino.cpp.o: In function convert_hue()': sketch/pwm.c:403: multiple definition of pwm_set_duty’
sketch/pwm.c.o:sketch/pwm.c:403: first defined here
sketch/Generic_RGBW_Light.ino.cpp.o: In function pwm_set_period': sketch/pwm.c:415: multiple definition of pwm_get_duty’
sketch/pwm.c.o:sketch/pwm.c:415: first defined here
sketch/Generic_RGBW_Light.ino.cpp.o: In function ~function': sketch/pwm.c:423: multiple definition of pwm_set_period’
sketch/pwm.c.o:sketch/pwm.c:423: first defined here
sketch/Generic_RGBW_Light.ino.cpp.o: In function pwm_init': sketch/pwm.c:161: multiple definition of pwm_init’
sketch/pwm.c.o:sketch/pwm.c:161: first defined here
sketch/Generic_RGBW_Light.ino.cpp.o: In function operator()': sketch/pwm.c:436: multiple definition of pwm_get_period’
sketch/pwm.c.o:sketch/pwm.c:436: first defined here
sketch/Generic_RGBW_Light.ino.cpp.o: In function operator()': sketch/pwm.c:442: multiple definition of get_pwm_version’
sketch/pwm.c.o:sketch/pwm.c:442: first defined here
sketch/Generic_RGBW_Light.ino.cpp.o: In function operator()': sketch/pwm.c:446: multiple definition of set_pwm_debug_en’
sketch/pwm.c.o:sketch/pwm.c:446: first defined here
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Generic ESP8266 Module.

Any help would be greatly appreciated. I really want to try out this project and already soldered some wires to a lightbulb for it!

pwm.c (10.8 KB)

Generic_RGBW_Light.ino (22.4 KB)

Your problem is line 8 of Generic_RGBW_Light.ino:

#include "pwm.c"

I'm not aware of any situation where it's a good idea to #include a .c file. If you need to use functions of the .c file in the .ino file then you #include the .h file which contains the function prototypes.

Also note that .ino files are actually C++ so you need to wrap those function prototypes in extern "C"{}. Typically this will be done in the .h file like this:

#ifdef __cplusplus
extern "C" {
#endif

// C function prototypes

#ifdef __cplusplus
}
#endif

You could also do this in the .ino file:

extern "C" {
#include "pwm.h"
}

That's less common because usually .h files are hidden away in a library so it's better to handle that sort of thing in the library instead of forcing it on the user.

I suggest that you post ALL your code.