McNeight / CAN_Library

Multiplatform Arduino library for supporting the native CAN controller on Due (SAM3X) and Teensy 3.1 (K2X) as well as MCP2515 through SPI
Other
95 stars 43 forks source link

Can't compile sample for Due #13

Open bsculley opened 6 years ago

bsculley commented 6 years ago

I have installed the library and am trying to compile the SendCANMessages example.

I'm getting the following errors:

Arduino: 1.8.5 (Windows 10), TD: 1.41, Board: "Arduino Due (Native USB Port)"

libraries\CAN_Library\CAN_SAM3X.cpp.o:(.rodata._ZTV9CAN_SAM3X+0x20): undefined reference to `CANClass::setMask(unsigned char, CAN_Filter)'

libraries\CAN_Library\CAN_SAM3X.cpp.o:(.rodata._ZTV9CAN_SAM3X+0x24): undefined reference to `CANClass::setMask(CAN_Filter)'

libraries\CAN_Library\CAN_SAM3X.cpp.o:(.rodata._ZTV9CAN_SAM3X+0x28): undefined reference to `CANClass::clearMask(unsigned char)'

libraries\CAN_Library\CAN_SAM3X.cpp.o:(.rodata._ZTV9CAN_SAM3X+0x2c): undefined reference to `CANClass::setFilter(unsigned char, CAN_Filter)'

libraries\CAN_Library\CAN_SAM3X.cpp.o:(.rodata._ZTV9CAN_SAM3X+0x30): undefined reference to `CANClass::setFilter(CAN_Filter)'

libraries\CAN_Library\CAN_SAM3X.cpp.o:(.rodata._ZTV9CAN_SAM3X+0x34): undefined reference to `CANClass::clearFilter(unsigned char)'

libraries\CAN_Library\CAN_SAM3X.cpp.o:(.rodata._ZTV9CAN_SAM3X+0x38): undefined reference to `CANClass::enableRXInterrupt()'

libraries\CAN_Library\CAN_SAM3X.cpp.o:(.rodata._ZTV9CAN_SAM3X+0x3c): undefined reference to `CANClass::disableRXInterrupt()'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino Due (Native USB Port).

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
DaleMitchell commented 6 years ago

I encountered the same errors from compiling the SendCANMessages example and noticed this section in CAN.h:

// Experimental
//
virtual void setMask(uint8_t maskID, CAN_Filter mask);
//
virtual void setMask(CAN_Filter mask);
//
virtual void clearMask(uint8_t maskID = 0);
//
virtual void setFilter(uint8_t filterID, CAN_Filter filter);
//
virtual void setFilter(CAN_Filter filter);
//
virtual void clearFilter(uint8_t filterID = 0);
//
virtual void enableRXInterrupt();
//
virtual void disableRXInterrupt();

There appear to be some functions in CAN.h that are not needed for the Due. In an effort to maintain functionality with other CAN controllers this library supports, I added preprocessor directives as follows:

#if defined(__SAM3X8E__) // Arduino Due
/*
#endif // __SAM3X8E__
// Experimental
//
virtual void setMask(uint8_t maskID, CAN_Filter mask);
//
virtual void setMask(CAN_Filter mask);
//
virtual void clearMask(uint8_t maskID = 0);
//
virtual void setFilter(uint8_t filterID, CAN_Filter filter);
//
virtual void setFilter(CAN_Filter filter);
//
virtual void clearFilter(uint8_t filterID = 0);
//
virtual void enableRXInterrupt();
//
virtual void disableRXInterrupt();
#if defined(__SAM3X8E__) // Arduino Due
*/
#endif // __SAM3X8E__

This fix should work for you as well.