undefined reference to `pluginInstance'

So I’m following the tutorial in ‘Developing Virtual Synthesizers with VCV Rack’ Book which is close to the manual tutorial. and I’ve gotten as far as using the helper.py file to createplugin and then createmodule. Upon using make to compile the code I receive undefined reference to `pluginInstance’ I’m really at a lost as I don’t see the problem with the code.

I’ve built Rack 2.2.2 and have compiled sample code from the book here I know its with line 32 I just don’t see whats wrong. Or if I’m missing out on some knowledge here. I’ll keep digging but bassface to hair pull about to happen.

#include "plugin.hpp"


struct MyModule : Module {
	enum ParamId {
		PARAMS_LEN
	};
	enum InputId {
		SINE_INPUT,
		INPUTS_LEN
	};
	enum OutputId {
		OUTPUTS_LEN
	};
	enum LightId {
		LIGHTS_LEN
	};

	MyModule() {
		config(PARAMS_LEN, INPUTS_LEN, OUTPUTS_LEN, LIGHTS_LEN);
		configInput(SINE_INPUT, "");
	}

	void process(const ProcessArgs& args) override {
	}
};


struct MyModuleWidget : ModuleWidget {
	MyModuleWidget(MyModule* module) {
		setModule(module);
		setPanel(createPanel(asset::plugin(pluginInstance,"res/myModule.svg")));
		addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
		addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
		addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
		addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
		addInput(createInputCentered<PJ301MPort>(mm2px(Vec(41.779, 118.776)), module, MyModule::SINE_INPUT));
	}
};


Model* modelMyModule = createModel<MyModule, MyModuleWidget>("myModule");

What does your plugin.json look like?

{
  "slug": "myModule",
  "name": "myModule",
  "version": "2.0.1",
  "license": "cc0-1.0",
  "brand": "myModule",
  "author": "int96",
  "authorEmail": "",
  "authorUrl": "",
  "pluginUrl": "",
  "manualUrl": "",
  "sourceUrl": "",
  "donateUrl": "",
  "changelogUrl": "",
  "modules": [
    {
      "slug": "myModule",
      "name": "myModule",
      "description": "A blank sine wave",
      "tags": [
        "Blank",
        "Sine Wave"
      ]
    }
  ]
}

I think it is the capital M. In json it is not capital. MyModule vs MyModule.

Edit: oh no sorry, I now see you have small in cpp at the end Should be ok.

Can you show plugin.hpp

#pragma once
#include <rack.hpp>


using namespace rack;

// Declare the Plugin, defined in plugin.cpp
extern Plugin* pluginInstance;

// Declare each Model, defined in each module source file
// extern Model* modelMyModule;

You have called it modelMyModule, you need to add:

extern model *modelMyModule;

It would also be (slightly?) interesting to see the plugin.cpp. But I guess since it links without error that @robert.kock has correctly spotted the issue.

Ok Ive tried several things and I’m unclear as to what I should change.

I updated my text, add that line in the hpp file and show your plugin.cpp

#include "plugin.hpp"



struct MyModule : Module {
	enum ParamId {
		PARAMS_LEN
	};
	enum InputId {
		SINE_INPUT,
		INPUTS_LEN
	};
	enum OutputId {
		OUTPUTS_LEN
	};
	enum LightId {
		LIGHTS_LEN
	};

	MyModule() {
		config(PARAMS_LEN, INPUTS_LEN, OUTPUTS_LEN, LIGHTS_LEN);
		configInput(SINE_INPUT, "");
	}

	void process(const ProcessArgs& args) override {
	}
};


struct MyModuleWidget : ModuleWidget {
	MyModuleWidget(MyModule* module) {
		setModule(module);
		setPanel(createPanel(asset::plugin(pluginInstance,"res/myModule.svg")));
		addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
		addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
		addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
		addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
		addInput(createInputCentered<PJ301MPort>(mm2px(Vec(41.779, 118.776)), module, MyModule::SINE_INPUT));
	}
};


Model* modelMyModule = createModel<MyModule, MyModuleWidget>("myModule");

that’s not your plugin.cpp

ok changed my plugin.hpp to

#pragma once
#include <rack.hpp>


using namespace rack;

// Declare the Plugin, defined in plugin.cpp
extern Plugin* pluginInstance;

// Declare each Model, defined in each module source file
extern Model* modelMyModule;

still no compile…i see that now leaving the comment derp.

yeah… ?? here ill send everything its small stuff anyways plugin.cpp (1.1 KB) plugin.hpp (233 Bytes)

oh! that is messed up, but you are correct.

I know what your issue is , but need to be at a computer to help If no one else has done within a couple of hours I will send you the solution. You need a proper plugin.cpp and rename your current plugin.cpp to myModule.cpp

what he said.

Ok I will investigate more on my end with the helloworld project. I think I see what you mean just need to figure it out. Thanks for the help you two.

1 Like

look at some plugin that is known to work. The Fundamentals are good, although slightly complex because there are so many modules in there. But look what’s in the plugin.cpp for that one, it should be typical.

1 Like

robert.kock

I know what your issue is , but need to be at a computer to help If no one else has done within a couple of hours I will send you the solution. You need a proper plugin.cpp and rename your current plugin.cpp to myModule.cpp

ok I renamed plugin.cpp to myModule.cpp and added this file

plugin.cpp

#include "plugin.hpp"


Plugin *pluginInstance;

void init(Plugin *p) {
	pluginInstance = p;

	p->addModel(modelMyModule);

}