vult-dsp / vult

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

Problem with multiple independently compiled files when included (redefinition error) #34

Open DatanoiseTV opened 4 years ago

DatanoiseTV commented 4 years ago

My build script for PlatformIO is compiling my used .vult "modules" independently and if another function uses Util. for example, I get a compiler error from the C++ compiler about redefinition of the Utility functions.

I've tried with "-tables false" for all but the first vult file, but that doesn't fix the issue.

vultc -ccode -i vultinc/phase -i vultinc/util vultsrc/{INFILE} -o gen_{INFILE}

In file included from lib/vultgen/vultgen.h:5:0,
                 from src/main.cpp:2:
lib/vultgen/gen_blit_vult.h:254:21: note: 'float Util_cvTokHz(float)' previously defined here
 static_inline float Util_cvTokHz(float cv){
                     ^

How do I deal with it?

modlfo commented 4 years ago

The way the compiler is architected is that rather than compiling/generating single files, a file and all it's dependencies are amalgamated into single file (or group of files, output.cpp and output.h). Rather than compiling each file separately, you have to compile the Vult files you use in your project at the same time. For example:

$ vultc synth1.vult synth2.vult -ccode

That will generate code for the synth1.vult and synth2.vult files including their dependencies. If both files use a third file called util.vult you will get the code for it as well with a single definition. Currently there's no way of generating the code for a single file. I didn't implemented it that way because I found it more convenient, when embedding the code in a project, to have a minimal set of files to compile.