Undefined reference to error

I’m trying to build my project and I encountered an undefined reference issue. I believe this issue might not be caused by platformio but I hope that the community can help out :grinning:

Here’s the build error:

    C:\Users\User\AppData\Local\Temp\ccQAkhzT.ltrans0.ltrans.o: In function `main':
    <artificial>:(.text.startup+0x2b2): undefined reference to `imu'
    <artificial>:(.text.startup+0x2c0): undefined reference to `imu'
    <artificial>:(.text.startup+0x2d0): undefined reference to `imu'
    <artificial>:(.text.startup+0x2de): undefined reference to `imu'
    <artificial>:(.text.startup+0x2ee): undefined reference to `imu'
    C:\Users\User\AppData\Local\Temp\ccQAkhzT.ltrans0.ltrans.o:<artificial>:(.text.startup+0x2f6): more undefined references to `imu' follow
    collect2.exe: error: ld returned 1 exit status
    scons: *** [.pio\build\uno\firmware.elf] Error 1
     [ERROR] Took 8.49 seconds

main.cpp gist:

    #include "IMU.h"

    void setup() {



    #include "MPU6050_6Axis_MotionApps20.h"

    class IMU {
        void init();
        void updateYPR();
        float getPitch();
        float getYaw();
        float getRoll();

        MPU6050 mpu;

    extern IMU imu;

Definitions of the declared method in IMU.h is written in IMU.cpp

I suspect it is due to main.cpp including IMU.h before the definition in IMU.cpp is declared/compiled.

It cannot find where you defined the imu object. Do you have the statement

IMU imu;

at the top of the IMU.cpp?

1 Like