queezythegreat / arduino-cmake

Arduino CMake Build system
648 stars 216 forks source link

cc1plus: error: unrecognized command line option '-mmcu=atmega2560' #25

Closed amcjen closed 12 years ago

amcjen commented 12 years ago

In trying to convert my project from the Arduino IDE over to using your cmake package, I get this:

$ make
[  3%] Building CXX object CMakeFiles/mega2560_CORE.dir/usr/share/arduino-1.0/hardware/arduino/cores/arduino/USBCore.cpp.o
cc1plus: error: unrecognized command line option ‘-mmcu=atmega2560’
make[2]: *** [CMakeFiles/mega2560_CORE.dir/usr/share/arduino-1.0/hardware/arduino/cores/arduino/USBCore.cpp.o] Error 1
make[1]: *** [CMakeFiles/mega2560_CORE.dir/all] Error 2
make: *** [all] Error 2

Here is my CMakeLists.txt

#=============================================================================#
# Author: QueezyTheGreat                                                      #
# Date:   26.04.2011                                                          #
#                                                                             #
# Description: Arduino CMake example                                          #
#                                                                             #
#=============================================================================#
set(CMAKE_MODULE_PATH    ${CMAKE_SOURCE_DIR}/cmake/modules)  # CMake module search path
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchains/Arduino.cmake) # Arduino Toolchain

cmake_minimum_required(VERSION 2.8)
#====================================================================#
#  Setup Project                                                     #
#====================================================================#
project(ArduinoController C CXX)
find_package(Arduino 1.0 REQUIRED)
#link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)
link_directories(/home/eric/sketchbook/libraries)

#====================================================================#
#  Settings                                                          #
#====================================================================#
set(FIRMWARE_NAME arduino_controller)

set(${FIRMWARE_NAME}_BOARD mega2560)                # Arduino Target board

set(${FIRMWARE_NAME}_HDRS Credentials.h)            # Firmware headers
set(${FIRMWARE_NAME}_SRCS arduino_controller.ino)  # Firmware sources

set(${FIRMWARE_NAME}_PORT /dev/ttyS0)               # Serial upload port

# set(${FIRMWARE_NAME}-serial picocom @INPUT_PORT@ -b 9600 -l)

#====================================================================#
#  Target generation                                                 #
#====================================================================#
generate_arduino_firmware(${FIRMWARE_NAME})

#add_subdirectory(example)  # Add example directory to build
johnyb commented 12 years ago

seems, you’re missing the cross-compiling toolchain. Make sure, you have avr-gcc and the avr-libc packages installed and cmake finds these.

amcjen commented 12 years ago

Hmm, I definitely have gcc-avr, binutils-avr, avr-libc, and avrdude installed (On Ubuntu Oneiric). They were installed via apt, so they're in the typical paths:

/usr/bin/avr-gcc /usr/bin/avrdude

Is there somewhere in the cmake config where I need to update the search path or something?

Thank you for the prompt reply too. Much appreciated!

amcjen commented 12 years ago

Ahh, nevermind. I cleared everything in the build directory, and reran cmake ..; make and it all worked.

Well, almost worked. I get an 'undefined reference to loop' error now, but at least it solved this one.

Thanks!

johnyb commented 12 years ago

please run cmake again with -DCMAKE_VERBOSE_MAKEFILE=ON and post the output after running make. This should clarify, what’s going on. (i hope ;))

johnyb commented 12 years ago

Ahh, great you have that one fixed :) to fix the undefined reference to loop, a loop function must be implemented and linked before the CORE library. You probably just need to move around your functions in your .ino-file and be fine.

amcjen commented 12 years ago

I had my main file named arduino_controller.ino. I renamed it to arduino_controller.cpp, updated the CMakeLists.txt *SRC to point to it, cleaned the build dir and reran cmake ..; make. No more loop error.

I see traditional gcc errors about functions not declared in the current scope, but looks to be from some of the magic the Arduino IDE does when compiling everything in a single file. I need to declare those in a .h file or something it seems.

Thank you for the help!

amcjen commented 12 years ago

Yep, declared those functions at the top of the file, and a clean complie! Thanks!

I may be back regarding getting the serial port stuff to work, but will give it a good go first to see if I can get it working.

Love the project, thanks!