ofAddListener, ofEvent: Undefined symbols for architecture x86_64

macOS High Sierra 10.13.6
XCode 9.4.1
of_v0.10.0_osx_release
base SDK: Latest macOS (macOS 10.13)
arch: x86_64 i386


Using ofAddListener causes the following error:

Undefined symbols for architecture x86_64:
    "ofApp::onVolumeChange(float&)", 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)

Following the ofEvents documentation I have the following app:

ofApp.h

#pragma once
#include "ofMain.h"
#include "ofEvents.h"
#include "MyClass.hpp"
class ofApp : public ofBaseApp{
    public:
	void setup();
	void update();
	void draw();
    void onVolumeChange(float & volume);
    MyClass myClass;
};

ofApp.cpp

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    ofAddListener(myClass.onVolumeChange, this, &ofApp::onVolumeChange); // this causes the error
}

//--------------------------------------------------------------
void ofApp::update(){}

//--------------------------------------------------------------
void ofApp::draw(){}

MyClass.hpp

#pragma once
#include "ofMain.h"
class MyClass {
    public:
    void setup();
    void update();
    ofEvent<float> onVolumeChange;
};

MyClass.cpp

#include "MyClass.hpp"
//------------------------------------------------------------------
void MyClass::setup(){}

//------------------------------------------------------------------
void MyClass::update(){
    float value = 10.0f;
    ofNotifyEvent(onVolumeChange, value);
}

What am I doing wrong?

edit: forgot to mention the weirdest part— the events examples all run fine. Examples from addons relying ofEvents (ofxSimpleTimer) run fine; the error occurs in new projects. If I copypaste everything verbatim into a new project the error appears.

you need to implement onVolumeChange in your ofApp.cpp

1 Like