vsariola / sointu

Fork of 4klang that can target 386, amd64 and WebAssembly. Tools run on Windows, Mac & Linux
MIT License
239 stars 15 forks source link

Unable to build VST2 plugin #96

Closed LJ1102 closed 10 months ago

LJ1102 commented 11 months ago

Tried to build the VST2 plugin using the command line from the readme and getting the following output:

C:\Users\lj110\Desktop\sointu-master>go build -buildmode=c-shared -tags=plugin -o sointu-vsti.dll .\cmd\sointu-vsti\
# github.com/vsariola/sointu/cmd/sointu-vsti
cmd\sointu-vsti\main.go:13:16: undefined: vst2.MIDIEvent
cmd\sointu-vsti\main.go:18:14: undefined: vst2.MIDIEvent
cmd\sointu-vsti\main.go:50:7: undefined: vst2.PluginAllocator
cmd\sointu-vsti\main.go:50:49: undefined: vst2.Plugin
cmd\sointu-vsti\main.go:50:62: undefined: vst2.Dispatcher
cmd\sointu-vsti\main.go:58:45: undefined: vst2.MIDIEvent
cmd\sointu-vsti\main.go:60:15: undefined: vst2.Plugin
cmd\sointu-vsti\main.go:69:41: undefined: vst2.FloatBuffer
cmd\sointu-vsti\main.go:82:12: undefined: vst2.Dispatcher
cmd\sointu-vsti\main.go:90:38: undefined: vst2.EventsPtr
cmd\sointu-vsti\main.go:90:38: too many errors

installed the VST2 thing(https://github.com/pipelined/vst2) using go get -u pipelined.dev/audio/vst2 and rerunning the build, same output.

Building the standalone tracker using go build -o sointu-track.exe cmd/sointu-track/main.go worked just fine, except that the GM samples are not playing on my system (Windows 10).

vsariola commented 11 months ago

Not able to reproduce. I checked out a fresh repo and copy-pasted your command to console & it passes without errors (Windows 10).

What version of go you have? I'm on 1.20.2 windows/amd64.

The latest Windows binaries, including vsti & native-vsti, can also be downloaded from here too: https://github.com/vsariola/sointu/suites/14455682343/artifacts/816237188

They are always built as part of actions.

vsariola commented 11 months ago

Oh, sointu has been pointing to a particular latest commit in the vst2. I think if you go get -u pipelined.dev/audio/vst2 it points the vst2 to the latest tag, but I had to send some pull requests to vst2 to make sointu work with & they were merged to master, yet I don't think sergej has published a new tag with the changes. So, I think something like go get -u pipelined.dev/audio/vst2@master might be a better idea.

vsariola commented 11 months ago

And samples do not work on the "non-native" version of the tracker/vsti; it has to be the native version. Someday, I'll fix this, but this is issue #75.

LJ1102 commented 11 months ago

Still getting the same error after getting master of vst2, according to go version I'm also 1.20.2. I'm fine with using the prebuild package though.

LeStahL commented 10 months ago

I have the problem as well (on Windows). The commands above do not solve it. Will investigate a little

vsariola commented 10 months ago

We have found a solution to this: setting environment variable CGO_ENABLED to 1 fixes the problem.

Then it still might give an error about missing compiler, but installing cgo compatible compiler e.g. gcc should do the trick. On windows, you best bet is MinGW, e.g. from tdm-gcc.

vsariola commented 10 months ago

I have updated the README.md to reflect the need for the environment variable CGO_ENABLED=1, closing this for now

vsariola commented 10 months ago

Clarification: the root cause of this is that cgo compatible compiler e.g. gcc is missing, along with PATH or CC environment variable pointing to that compiler. Golang tries to find the C-compiler, but being unable to find it, automatically considers CGO_ENABLED=0. When this happens, all files that include C-code are just excluded from the build, resulting in missing types.

Forcing CGO_ENABLED=1 is a good idea, as it gives better error messages of the root cause (missing compiler).

Relevant documentation: https://pkg.go.dev/cmd/cgo

The crucial paragraph:

The cgo tool is enabled by default for native builds on systems where it is expected to work. It is disabled by default when cross-compiling as well as when the CC environment variable is unset and the default C compiler (typically gcc or clang) cannot be found on the system PATH. You can override the default by setting the CGO_ENABLED environment variable when running the go tool: set it to 1 to enable the use of cgo, and to 0 to disable it. The go tool will set the build constraint "cgo" if cgo is enabled. The special import "C" implies the "cgo" build constraint, as though the file also said "//go:build cgo". Therefore, if cgo is disabled, files that import "C" will not be built by the go tool. (For more about build constraints see https://golang.org/pkg/go/build/#hdr-Build_Constraints).