Problems using the MadgwickAHRS library

Hej there

I’m building a device, which should give me its orientation in 360 degrees. To accomplish that, I want to use the Open Source MadgwickAHRS library from

But I don’t even get to compile my code. I’m getting this error message:
“undefined reference to `MadgwickAHRSupdate(float, float, float, float, float, float, float, float, float)’”

I have added the MadgwickAHRS library to my arduino librarys. I’m not the most experienced coder and I have no clue why this error message appears.

Here’s my code:

#include <Wire.h>
#include <LSM303.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_L3GD20_U.h>
#include "MadgwickAHRS.h"

#include "math.h"

Adafruit_L3GD20_Unified gyro = Adafruit_L3GD20_Unified(20);
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(54321);
Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(12345);
//Serial.write Übertragung

float pitch, roll, yaw;
float gx;
float gy;
float gz;
float ax;
float ay;
double az;
float mx, my, mz;

void displaySensorDetails(void)
  sensor_t sensor;


void setup() {



void loop() {
  sensors_event_t event; 

  gx = 0.1;
  gy = 0.1;
  gz = 0.5;
  ax = 0.1;
  ay = 0.1;
  az = 0.5;

  mx = 0.1;
  my = 0.1;
  mz = 0.5;

  MadgwickAHRSupdate(gx, gy, gz, ax, ay, az, mx, my, mz);

  Serial.print(roll); Serial.print("\t"); 




void GetEuler(void){
  roll = atan2(2 * (q0 * q1 + q2 * q3), 1 - 2 * (q1 * q1 + q2 * q2)) * 360/(2*PI);
  pitch = asin(2 * (q0 * q2 - q3 * q1)) * 360/(2*PI);
  yaw = atan2(2 * (q0 * q3 + q1 * q2), 1 - 2* (q2 * q2 + q3 * q3)) * 360/(2*PI);
  if (yaw < 0){
    yaw +=360;

I really appreciate any help you could offer me, since I should finish this project in 1,5 weeks :cold_sweat:


Code looks ok at first glance. Scroll up in the error window a bit - is that the first error message?

I suspect that your sketch isn't finding the library.

It's the only error I get.

here's the full error:

ahrs_h.cpp.o: In function loop': /Applications/ahrs_h.ino:70: undefined reference to MadgwickAHRSupdate(float, float, float, float, float, float, float, float, float)'

If I change the name of the funtion to one that doesn't exist in the library, I get a different error:
error: 'MadgwickHRSupdate' was not declared in this scope

So it seems that in the first case, the compiler finds the function in the header. Maybe it doesn't find the actual c code of the function. Could that be possible? But i have the .c file in the same ordner as the .h file. So that shouldn't happen, should it?