stuck on undefined reference error

Hi guys,

So I gather an undefined reference has to do with not being able to find a definition. However I’ve checked my program dozens of times and I can’t figure out what is wrong.

  
myFirstClass.cpp :  
  
#include "myFirstClass.h"  
  
myFirstClass::myFirstClass(){  
    this.myInt = 15;  
}  
  
  
  
  
myFirstClass.h :   
  
#include "ofMain.h"  
  
class myFirstClass{  
public :  
    myFirstClass();  
    int myInt;  
};  
  
  
  
  
In the public section of testApp.h :  
  
myFirstClass myFirstClassTest;  
  
  
  
  
in my testApp.cpp draw() function :  
  
myFont.drawString(ofToString(myFirstClassTest.myInt),400,200);  
  

I get undefined reference to ‘myFirstClass::myFirstClass()’ .

myFirstClass.cpp and myFirstClass.h are located in the /src folder of the app.

I really can’t find what’s wrong :frowning:

I guess it’s because there’s no #include “myFirstClass.h” in testApp.h, so testApp doesn’t know about myFirstClass

I guess it’s because there’s no #include “myFirstClass.h” in testApp.h, so testApp doesn’t know about myFirstClass

Like bilderbuchi says, any time you add a reference to an external class you need to add a way for the compiler to find it:

  
#include "myFirstClass.h"  

also, in “myFirstClass.h” you should add a header guard:

  
#pragma once  

to prevent the compiler from including it multiple times and causing problems.

Alright guys, I found what was blocking me. In CodeBlocks files you add in the /src folder after you create a project don’t get automatically detected and I had to manually add them to the project for it to work.