vult-dsp / vult

Vult is a transcompiler well suited to write high-performance DSP code
https://vult-dsp.github.io/vult
Other
490 stars 25 forks source link

Error calling `random()` method in VCV Rack #47

Closed stephanepericat closed 2 years ago

stephanepericat commented 2 years ago

Hi,

I wrote a simple method returning a random number:

fun process() : real {
  return (random() - 0.5) * 10.0;
}

The generated c++ code looks like this:


/* Code automatically generated by Vult https://github.com/modlfo/vult */
#ifndef NOISE_H
#define NOISE_H
#include <stdint.h>
#include <math.h>
#include "vultin.h"
#include "noise.tables.h"

static_inline float Noise_process(){
   return (10.f * (-0.5f + float_random()));
};

#endif // NOISE_H

I have vultin.h in the same folder as noise.h.

However, when I call Noise_process() in my VCV plugin, rebuild and launch VCV, the plugin cannot be loaded, and i see the following error in the VCV logs:

[0.895 info src/plugin.cpp:120 loadPlugin] Loading plugin from /Users/sppericat/Documents/Rack2/plugins/shortwav-audio
[0.958 warn src/plugin.cpp:173 loadPlugin] Could not load plugin /Users/sppericat/Documents/Rack2/plugins/shortwav-audio: Failed to load library /Users/sppericat/Documents/Rack2/plugins/shortwav-audio/plugin.dylib: dlopen(/Users/sppericat/Documents/Rack2/plugins/shortwav-audio/plugin.dylib, 6): Symbol not found: __Z12float_randomv
  Referenced from: /Users/sppericat/Documents/Rack2/plugins/shortwav-audio/plugin.dylib
  Expected in: flat namespace
 in /Users/sppericat/Documents/Rack2/plugins/shortwav-audio/plugin.dylib

any idea why this is happening ? it works fine if i use the random::normal() method from the VCV SDK.

modlfo commented 2 years ago

You need to add to your sources the vultin.cpp file https://github.com/vult-dsp/vult/blob/master/runtime/vultin.cpp

Just put it in the same folder as your other .cpp files and it should work.

stephanepericat commented 2 years ago

I have it in the same folder as vultin.h; is it not ok ?

Screen Shot 2022-01-09 at 1 13 28 PM
stephanepericat commented 2 years ago

I added the lib folder in my Makefile, and now it works:

# Add .cpp files to the build
SOURCES += $(wildcard src/*.cpp)
SOURCES += $(wildcard src/lib/*.cpp)

Thanks!