How dealing with class in Of or CPP

Hello and happy new-year.
I’m back to open Framework after one year, and I’ve a strange behavior with class and give build failed. I’ve no idea… in the same time I’m not an expert in CPP and OF.

My system is OS Monterey 12.2
OF 11.2

Before that, I’ve big program work fine on High Sierra / OF 11, and the same program now crash with this new configuration

a snippet code to reproduce my problem :
the console return :

Undefined symbols for architecture x86_64:
  "C_Truc::C_Truc()", referenced from:
      ofApp::setup() in ofApp.o
  "C_Truc::get_name() const", referenced from:
      ofApp::setup() in ofApp.o
  "C_Truc::~C_Truc()", referenced from:
      ofApp::setup() in ofApp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I don’t understand why because I’ve a feeling my code is right

#include "ofApp.cpp"
void ofApp::setup() {
	C_Truc truc;
	std::string mess = truc.get_name();
	std::cout << mess << std::endl;
void ofApp::update(){}
void ofApp::draw(){}


#pragma once

#include "C_Truc.hpp"
#include "ofMain.h"

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


#ifndef C_TRUC_H
# define C_TRUC_H
#pragma once

#include <iostream>

class C_Truc {

	std::string _name;

	std::string get_name() const;;



#include "C_Truc.hpp"

C_Truc::C_Truc() {
	C_Truc::_name = "machin";
	std::cout << "C_Virus default constructor" << std::endl;

C_Truc::~C_Truc() {
	std::cout << "C_Truc destructor" << std::endl;

std::string C_Truc::get_name() const {
	return this->_name;

For more information, I’ve the same problem in C++ with clang++ when I use class that compiler return Undefined symbols for architecture x86_64: "random(float, float, std::__1::linear_congruential_engine<unsigned int, 48271u, 0u, 2147483647u>&)", referenced from: vec2<float>::rand(float const&, float const&, float const&, float const&, std::__1::linear_congruential_engine<unsigned int, 48271u, 0u, 2147483647u>&) in main-688604.o

But I found no information about that on the web.

I post the question on c++ - Undefined symbols for architecture x86_64 with OS Monterey - Stack Overflow

This here works for me on macOS 10.15.7 with OF 0.11.0 on Xcode 12.4

I think it’s just about adding #include "ofMain.h" in to your class header file

Thx @ stephanschulz for the feed back me too that’s work before on my OS HighSierra with OF 0.11.0 too, but after I reinstall my OS from scratch, this problem happen :frowning:

I test with your code, that result is the same. So it’s not about ofMain.h who not include… it’s a pity. I test with a simple C++ code… I can reproduce this family fail error undefined... when file.cpp is not build. But I don’t know how check is all files are compiled.

OS Monterey 12.1
OF 0.11.2
X-Code 13.2.1

That’s done… IT’s my fault, to much time out of X-Code and Open framework. I forget it’s necessary to import file and with a create group option if there is folder for the file.