-
Notifications
You must be signed in to change notification settings - Fork 39
undefined reference to main
#37
Description
Greetings,
I am going to preface this by saying im not entirely sure if I am doing this right and tried to build one of your example projects to get a better understanding of how this project works
What I have is I created a new c++ project in clion, i have replaced the cmake build file and source file with that of your hello world example and encountered a build-breaking error during linking. ( did reload the cmake project prior to building)
issue:
It appears the linker raises objection if a int main()
is not declared, which is to be expected for a native OS application, however Arduino writes to firmware if i am not mistaken. Therefore having a int main()
is unnecessary? The example projects also do not reflect the need for an int main()
steps to reproduce:
- copy the hello world example to its own directory
- attempt to build the hello world project
Contents of CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
project(Hello_World LANGUAGES C CXX ASM)
get_board_id(board_id nano atmega328)
add_arduino_executable(Hello_World ${board_id} helloWorld.cpp)
#upload_arduino_target(Hello_World "${board_id}" COM3)
Contents of helloWorld.cpp
#include <Arduino.h>
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Build log:
D:\programfiles\Jetbrains\apps\CLion\ch-0\182.4505.18\bin\cmake\win\bin\cmake.exe --build D:\Clion\sandbox\arduino_sandbox\cmake-build-debug --target all -- -j 4
Scanning dependencies of target nano_atmega328_core_lib
[ 25%] Building ASM object CMakeFiles/nano_atmega328_core_lib.dir/D_/Program_Files_(x86)/Arduino/hardware/arduino/avr/cores/arduino/wiring_pulse.S.obj
[ 50%] Linking ASM static library libnano_atmega328_core_lib.a
[ 50%] Built target nano_atmega328_core_lib
Scanning dependencies of target Hello_World
[ 75%] Building CXX object CMakeFiles/Hello_World.dir/helloWorld.cpp.obj
[100%] Linking CXX executable Hello_World.elf
d:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr5/crtatmega328p.o:(.init9+0x0): undefined reference to `main'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [Hello_World.elf] Error 1
CMakeFiles\Hello_World.dir\build.make:83: recipe for target 'Hello_World.elf' failed
CMakeFiles\Makefile2:108: recipe for target 'CMakeFiles/Hello_World.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/Hello_World.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2
Makefile:82: recipe for target 'all' failed
additonal cmake arguments added:
as per the wiki i added the following to my cmake build options
-DCMAKE_TOOLCHAIN_FILE=Arduino-CMake-NG/cmake/Arduino-Toolchain.cmake
OS: Windows
Distribution N/A
OS Version: 10
Platform: Arduino
SDK Version: Arduino SDK version 1.8.7
Once again, sorry if this is user error :(