Closed nilrog closed 12 years ago
can you try to add this to your CMakeLists.txt
set(SD_RECURSE True)
this might work, though I haven’t tried, yet.
Yes, that worked. Just spotted it in the docs too :)
After reading the cake sources I believe this is a bug...because for the Wire and Ethernet libraries the recurse option is set. So that should be the case for SD too.
Recurse patch was merged in, closing issue.
I get similar errors, but set(SD_RECURSE True)
doesn't work. I made a small test.
cmake_minimum_required(VERSION 2.8.4)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/ArduinoToolchain.cmake)
set(PROJECT_NAME SDtest)
project(${PROJECT_NAME})
`
set(${CMAKE_PROJECT_NAME}_ARDLIBS SD)
set(${CMAKE_PROJECT_NAME}_SKETCH SDtest.ino)
generate_arduino_firmware(${CMAKE_PROJECT_NAME})`
#include <Arduino.h>
#include <SD.h>
void setup() {
SD.begin(4);
}
void loop() {}
[ 97%] Linking CXX executable SDtest.elf
libuno_SD.a(Sd2Card.cpp.obj): In function
SPIClass::endTransaction()':
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h:275: undefined reference to SPIClass::interruptMode'``
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h:275: undefined reference to SPIClass::interruptSave'
libuno_SD.a(Sd2Card.cpp.obj): In function
SPIClass::beginTransaction(SPISettings)': /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h:179: undefined reference to
SPIClass::interruptMode'
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h:184: undefined reference to SPIClass::interruptMode' /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h:185: undefined reference to
SPIClass::interruptSave'
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h:186: undefined reference to SPIClass::interruptMask' /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h:191: undefined reference to
SPIClass::interruptSave'
libuno_SD.a(Sd2Card.cpp.obj): In function SPIClass::endTransaction()': /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h:269: undefined reference to
SPIClass::interruptMode'
libuno_SD.a(Sd2Card.cpp.obj): In function Sd2Card::init(unsigned char, unsigned char)': /Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/Sd2Card.cpp:268: undefined reference to
SPIClass::begin()'
libuno_SD.a(Sd2Card.cpp.obj): In function SPIClass::endTransaction()': /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h:269: undefined reference to
SPIClass::interruptMode'
collect2: error: ld returned 1 exit status
make[3]: * [SDtest.elf] Error 1
make[2]: * [CMakeFiles/SDtest.dir/all] Error 2
make[1]: * [CMakeFiles/SDtest.dir/rule] Error 2
make: * [SDtest] Error 2
With the arduino IDE it compiles and links correctly. Any idea what is happening?
Anyhow, by adding
#include <SPI.h>
and
SPI.begin();
(or some other SPI command) to the main program, clion links it correctly.
I just made a quick test to see if this tool was useful and not since I really want to get rid of the Arduino IDE but still be able to use all the libraries out there. So I simply created a target using the CardInfo example from the SD library included with Arduino 1.0 (and adding the Arduino.h include to the file). But the code won't link correctly, most likely because the SD library has code also in a subdirectory called "utility" which I guess your cmake tool cannot detect.
Here is the error:
Linking CXX executable sd_cardinfo.elf CMakeFiles/sd_cardinfo.dir/sd_cardinfo.cpp.obj: In function
SdFile': /Applications/Arduino.app/Contents/Resources/Java/libraries/SD/utility/SdFat.h:138: undefined reference to
vtable for SdFile' /Applications/Arduino.app/Contents/Resources/Java/libraries/SD/utility/SdFat.h:138: undefined reference tovtable for SdFile' CMakeFiles/sd_cardinfo.dir/sd_cardinfo.cpp.obj: In function
setup': /Users/nilrog/Documents/Arduino/arduino-cmake/sd_cardinfo/sd_cardinfo.cpp:50: undefined reference toSd2Card::init(unsigned char, unsigned char)' CMakeFiles/sd_cardinfo.dir/sd_cardinfo.cpp.obj: In function
SdVolume::init(Sd2Card)': /Applications/Arduino.app/Contents/Resources/Java/libraries/SD/utility/SdFat.h:450: undefined reference to `SdVolume::init(Sd2Card, unsigned char)' /Applications/Arduino.app/Contents/Resources/Java/libraries/SD/utility/SdFat.h:450: undefined reference toSdVolume::init(Sd2Card*, unsigned char)' CMakeFiles/sd_cardinfo.dir/sd_cardinfo.cpp.obj: In function
SdFile::openRoot(SdVolume&)': /Applications/Arduino.app/Contents/Resources/Java/libraries/SD/utility/SdFat.h:345: undefined reference toSdFile::openRoot(SdVolume*)' CMakeFiles/sd_cardinfo.dir/sd_cardinfo.cpp.obj: In function
setup': /Users/nilrog/Documents/Arduino/arduino-cmake/sd_cardinfo/sd_cardinfo.cpp:106: undefined reference to `SdFile::ls(unsigned char, unsigned char)' make[2]: * [sd_cardinfo/sd_cardinfo.elf] Error 1 make[1]: * [sd_cardinfo/CMakeFiles/sd_cardinfo.dir/all] Error 2If I try the same using one of the EEPROM examples from Arduino the code compiles and links correctly.