Errors when building tutorial plugin

Solution: I used helper.py in the /Rack directory instead of the plugin directory, so the plugin.hpp file didn’t know where to look to find <rack.hpp>.

So I’ve got Rack built from source on a Linux computer and the Fundamental modules are working as they should. I created the MyPlugin plugin with helper.py, made a suitable .svg file in Inkscape, and edited the src/MyModule.cpp file as instructed.

When I enter make, it spits out tons of errors, starting with:

src/MyModule.cpp:4:26: error: expected class-name before ‘{’ token struct MyModule : Module {

It says “‘processArgs’ does not name a type”, and “‘Model’ does not name a type”.

Then there are a ton of names and functions and things that are “not included in this scope”.

All I can think is that there must be a missing header file somewhere, but everything looks like it’s been included. MyModule.cpp includes “plugin.hpp”, which in turn includes <rack.hpp>, which includes all the other header files I should need.

Thank you in advance for any insight you can provide!

Are you missing a closing brace or semicolon before declaring your MyModule struct?

Surround terminal output and source code with ` (inline) or ``` on its own line (block).

Could you attach your C++ file?

I’m a new user so it won’t let me upload a file, but I’ll copy and paste it here:

#include "plugin.hpp"

struct MyModule : Module {
	float phase = 0.f;
	float blinkPhase = 0.f;
	enum ParamIds {
		FREQKNOB_PARAM,
		NUM_PARAMS
	};
	enum InputIds {
		VOCTIN_INPUT,
		NUM_INPUTS
	};
	enum OutputIds {
		OUT_OUTPUT,
		NUM_OUTPUTS
	};
	enum LightIds {
		BLINKO_LIGHT,
		NUM_LIGHTS
	};

	MyModule() {
		config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
		configParam(FREQKNOB_PARAM, 0.f, 1.f, 0.f, "");
	}

	void process(const ProcessArgs &args) override {
		// Compute the frequency from the pitch parameter and input
		float pitch = params[FREQKNOB_PARAM].getValue();
		pitch += inputs[VOCTIN_INPUT].getVoltage();
		pitch = clamp(pitch, -4.f, 4.f);
		//the default pitch is C4 = 261.6256f
		float freq = dsp::FREQ_C4 * std::pow(2.f, pitch);
		
		//Accumulate the phase (??)
		phase += freq * args.sampleTime;
		if (phase >= 0.5f)
			phase -= 1.f;

		//Compute the sine output
		float sine = std::sin(2.f * M_PI * phase);
		//Audio signals are typically +/-5V
		// https://vcvrack.com/manual/VoltageStandards.html
		outputs[OUT_OUTPUT].setVoltage(5.f * sine);

		//Blink light at 1Hz
		blinkPhase += args.sampleTime;
		if(blinkPhase >= 1.f)
			blinkPhase -= 1.f;
		lights{BLINKO_LIGHT].setBrightness(blinkPhase < 0.5f ? 1.f : 0.f);
	}
};


struct MyModuleWidget : ModuleWidget {
	MyModuleWidget(MyModule* module) {
		setModule(module);
		setPanel(APP->window->loadSvg(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)));

		addParam(createParamCentered<RoundBlackKnob>(mm2px(Vec(33.662, 38.11)), module, MyModule::FREQKNOB_PARAM));

		addInput(createInputCentered<PJ301MPort>(mm2px(Vec(17.1, 101.245)), module, MyModule::VOCTIN_INPUT));

		addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(44.795, 104.197)), module, MyModule::OUT_OUTPUT));

		addChild(createLightCentered<MediumLight<RedLight>>(mm2px(Vec(32.237, 66.45)), module, MyModule::BLINKO_LIGHT));
	}
};


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

declaring the struct is the very first thing that happens after the header declaration (see my reply to Vortico) so I don’t think so.

Huh, weird. I thought I enabled uploads for the “new user” role. I’ll test this later.

Your error is likely with the plugin.hpp header file, such as a missing semicolon or bracket. Could you post that file?

I’m not sure this is relevant, but MyModule.cpp is currently located in the main /Rack directory, which seems a little weird to me. Here’s my plugin.hpp file:

#pragma once
#include <rack.hpp>


using namespace rack;

// Declare the Plugin, defined in plugin.cpp
extern Plugin* pluginInstance;
extern Model* modelMyModule;
// Declare each Model, defined in each module source file
// extern Model* modelMyModule;

Yeah, that’s a weird location for MyModule.cpp. It should be somewhere in your plugin’s directory, such as src/. Your plugin.hpp looks fine to me.

There’s an error in the MyModule.cpp file. The last line of your process method has a curly brace instead of a bracket

lights{BLINKO_LIGHT].setBrightness...

2 Likes