Trying to link utilities class to be referenced by all the other classes

I am trying to make a Class (Utils.cpp) to be filled with “global” functions and constants that can be referenced from anywhere in my program:
I’m not too familiar with pointers so please explain your answers at length :slight_smile:

Utils.cpp:

#include "Utils.hpp"
Utils::Utils(){

}
void Utils::setup(){
  ofSetDataPathRoot("./data");
  font.load("Assets/Menlo.tcc",8);
  logo.load("Assets/Logo.png");
}

Utils.hpp

#ifndef Utils_hpp
#define Utils_hpp

#include <stdio.h>
#include <ofMain.h>

class Utils{
  public:
    void setup();
    ofTrueTypeFont font;
    ofImage logo;
  
  Utils();
};

#endif /* Utils_hpp */

ofApp.cpp:

void ofApp::setup(){
  util.setup();
}
//Update Function (with nothing in it)
void ofApp::draw(){
  ofSetColor(255);
  util.logo.draw(0,0,50,50);
  util.font.drawString("Stuff",50,10);
}

ofApp.hpp:

#include "ofMain.h"

#include "Utils/Utils.hpp"

class ofApp : public ofBaseApp{
  public:
	void setup();
	void update();
	void draw();
  Utils util;
};

If anyone could help me - the error Im getting is (In Xcode)
Undefined symbols for architecture x86_64:
“Utils::setup()”, referenced from:
ofApp::setup() in ofApp.o
“Utils::Utils()”, referenced from:
ofApp::ofApp() in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Thanks! (Does this count as an advanced question?)

Hello @Zyansheep, this error is saying that you declared something in one class ofApp that has not beeing implemented.

Try to add update() implementation to your ofApp class

I do have an update() implementation in my ofApp class I just wanted to save reading time ¯_(ツ)_/¯
My main goal is to have functions and objects that can be called/used in any class in my program basically global constants.

I’m looking for an example of code that works in which I can call and use objects (like ofImage and ofTrueTypeFont) from anywhere in my program.

did you add the path to the class you are referencing (Utils.h) in the “Additional Include Directories” for the architecture you are building?

“Additional Include Directories” is the name used in Visual Studio. Xcode might be a bit different. Also I would place this question in the Beginner category since my guess is that you are starting to work with openframeworks. Advanced questions are usually topics difficult to solve, that could involve deep knowledge of computing/graphics/network issues… something that only experts can solve.

Thanks so much! I can’t believe I didn’t think of that.
When I made the files Xcode didn’t know to compile them.