tenbaht / sduino

An Arduino-like programming API for the STM8
http://tenbaht.github.io/sduino/
GNU Lesser General Public License v2.1
349 stars 213 forks source link

Errors come while compile the code. #89

Closed Joypacharya closed 4 years ago

Joypacharya commented 4 years ago

I am developing code for temp checking the tuya interface with the board STM8S103F3. I select the appropriate board onboard menu. So, I correct all the required changes into code. Then after I was getting this kind of error,

Compiling libraries... Compiling core... Using precompiled core: C:\Users\admin\AppData\Local\Temp\arduino_cache_468473\core\core_sduino_stm8_stm8sblue_42b023c17f6c28f22a2e1bdc7d8ce243.a Linking everything together... "C:\Users\admin\AppData\Local\Arduino15\packages\sduino\tools\STM8Tools\2019.02.05/win/busybox" ash "C:\Users\admin\AppData\Local\Arduino15\packages\sduino\tools\STM8Tools\2019.02.05/wrapper/sdcc-link.sh" "C:\Users\admin\AppData\Local\Arduino15\packages\sduino\tools\sdcc\build.11242/bin/sdcc" --nostdlib "-LC:\Users\admin\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.5.0/STM8S_StdPeriph_Driver/lib" "-LC:\Users\admin\AppData\Local\Temp\arduino_build_27779" "-LC:\Users\admin\AppData\Local\Arduino15\packages\sduino\tools\sdcc\build.11242/lib/stm8" --code-size 8192 --iram-size 1024 -mstm8 -DSTM8S103 "C:\Users\admin\AppData\Local\Temp\arduino_build_27779\sketch\02.ino.cpp.o" "C:\Users\admin\AppData\Local\Temp\arduino_build_27779\sketch\mcu_api.cpp.o" "C:\Users\admin\AppData\Local\Temp\arduino_build_27779\sketch\protocol.cpp.o" "C:\Users\admin\AppData\Local\Temp\arduino_build_27779\sketch\system.cpp.o" "C:\Users\admin\AppData\Local\Temp\arduino_build_27779/..\arduino_cache_468473\core\core_sduino_stm8_stm8sblue_42b023c17f6c28f22a2e1bdc7d8ce243.a" -lSTM8S103 -lstm8 --out-fmt-elf -o "C:\Users\admin\AppData\Local\Temp\arduino_build_27779/02.ino.elf" Multiple definition of _dummy_variable Multiple definition of _dummy_variable Multiple definition of _dummy_variable

I think these errors generate because of some problem in the library. I hope you will help me. Thank you.

tenbaht commented 4 years ago

It looks like your source code contains cpp files: mcu_api.cpp, protocol.cpp and system.cpp. SDCC is a plain C compiler, cpp language elements don't work. The build script wrapper/sdcc.sh simply renames cpp file to c and inserts a refence to dummy_variable in order to pull in the default main() from the the sduino library.

Using dummy_variable is a workaround to simulate weak linking in order to supply a default main() from the sduino libraries. It is supposed to be added automatically to the main sketch file (typ. the ino file), which is supposed to be the only file in the build process with a cpp file ending.

Since your cpp files compile ok, they seem to be pure C. So there is an easy fix: Rename them to *.c and it should work out.