I have a small project to test a Sparkfun MPU9250 breakout board. 'Class_MPU9250BasicAHRS_t3.h', 'MPU9250BasicAHRS_t3.h' and 'Class_MPU9250BasicAHRS_t3.cpp' are all in the local project folder. Compile fails with an 'undefined reference' error at any reference to the Class_MPU9250BasicAHRS myIMU object unless I add 'Class_MPU9250BasicAHRS_t3.cpp' to the project as a 'Source File' in the Solution Explorer window.
Why is this? I thought the compiler was smart enough to look for a .cpp file with the same name as an #include'd header file.
TIA,
Code attached:
/*
Name: Teensy_MPU9250_Test.ino
Created: 9/15/2019 11:46:10 AM
Author: FRANKWIN10\Frank
*/
/* All this program does is display heading values from a Sparkfun MPU9250
breakout board at the default (0x68) I2C address
*/
#include "Class_MPU9250BasicAHRS_t3.h" //extracted all #defines from MPU9250BasicAHRS_t3.ino
#include <i2c_t3.h>
#include <elapsedMillis.h>
elapsedMillis sinceLastPrint;
Class_MPU9250BasicAHRS myIMU;
int pulsePin = LED_BUILTIN;//04/10/18 added per-step pulse pin parameter
bool bFirstTime = true;
const long MSEC_PER_PRINT = 100;
void setup()
{
Serial.begin(115200);
delay(3000); //delay required to wait for Serial object creation
//Wire.begin();
pinMode(LED_BUILTIN, OUTPUT);
Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_EXT, 400000);
Wire.setDefaultTimeout(200000); // 200ms
//IMU init & test
Serial.println("Starting program...");
Serial.println("Initializing 9250 IMU...");
myIMU.init9250IMU();
Serial.println("Done...");
}
void loop()
{
float hdg_deg = myIMU.GetIMUHeadingDeg();
if (bFirstTime)
{
bFirstTime = false;
Serial.printf("Msec\tHdg\n");
}
if (sinceLastPrint > MSEC_PER_PRINT)
{
Serial.printf("%lu\t%4.2f\n", millis(), hdg_deg);
sinceLastPrint -= MSEC_PER_PRINT;
}
}