Building VST2 from cmake is broken (Mac)

Hello

This is a problem in 3.6.9 (but was the same problem with 3.6.8). Here are the steps to reproduce:

Assuming VST3 SDK is installed under /Applications/VST_SDK.369

mkdir -p /tmp/vst369.sdk/Debug
cd /tmp/vst369.sdk/Debug

# enable VST2 and disable automatic run of validator (workaround for other issue)
cmake -DSMTG_RUN_VST_VALIDATOR=OFF -DSMTG_CREATE_VST2_VERSION=ON /Applications/VST_SDK.369/VST3_SDK

# build again
cmake --build . --target again

# build validator
cmake --build . --target validator

# run validator => valid VST3 plugin
./bin/validator VST3/again.vst3
* Loading module...
...
-------------------------------------------------------------
Result: 78 tests passed, 0 tests failed
-------------------------------------------------------------

# run MrsWatson => invalid VST2 plugin
mrswatson64 --display-info -p VST3/again.vst3
- 00000000 000000 MrsWatson version 0.9.8 initialized, build 20150122
- 00000000 000000 Plugin 'VST3/again.vst3' is of type VST2.x
- 00000000 000000 Opening VST2.x plugin 'VST3/again.vst3'
E 00000000 000005 Couldn't get a pointer to plugin's main()
E 00000000 000005 Could not load VST2.x plugin '/Volumes/Vault/tmp/blog/VST3/again.vst3'
E 00000000 000005 Plugin 'VST3/again.vst3' could not be opened
E 00000000 000005 Plugin 'VST3/again.vst3' could not be added to the chain
E 00000000 000005 Plugin chain could not be constructed, exiting

I am using the project MrsWatson (https://github.com/teragonaudio/MrsWatson) to load a VST2 plugin but it obviously will not load either in DAWs supporting only VST2 (Reason / Maschine).

The issue is that the VSTPluginMain function is not exported. The CMakeLists.txt section handling this issue:

if (SMTG_CREATE_VST2_VERSION)
    message(STATUS "SMTG_CREATE_VST2_VERSION is set. A VST 2 version of the plug-in will be created (just rename the generated file from .vst3 to .vst).")
    if(XCODE)
        # fix missing VSTPluginMain symbol when also building VST 2 version
        set_target_properties(${target} PROPERTIES XCODE_ATTRIBUTE_EXPORTED_SYMBOLS_FILE "")
    endif()
    if (WIN)
        add_definitions(-D_CRT_SECURE_NO_WARNINGS)
    endif()
endif()

is as you can see XCODE specific (not MAC specific).

In order to fix this issue I did the following:

  • add a file public.sdk/source/main/macexport_vst2.exp with the following content (exporting the VST3 specific symbols + the VST2 specific one to make the plugin work either as a VST3 or VST2 plugin)
_GetPluginFactory
_bundleEntry
_bundleExit
_VSTPluginMain
  • change the again/CMakeLists.txt section to use it (and be MAC specific vs XCODE specific)
if (SMTG_CREATE_VST2_VERSION)
  message(STATUS "SMTG_CREATE_VST2_VERSION is set for ${target}. A VST 2 version of the plug-in will be created (just rename the generated file from .vst3 to .vst).")
  if(MAC)
  # fix missing VSTPluginMain symbol when also building VST 2 version
    smtg_set_exported_symbols(${target} "${SDK_ROOT}/public.sdk/source/main/macexport_vst2.exp")
  endif()
  if (WIN)
    add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  endif()
endif()

Yan
PS: My blog describes another way to fix this issue without modifying the SDK… https://www.pongasoft.com/blog/yan/vst/2018/03/12/VST-development-notes

thanks for the fix, we were checking for now only the xcode variant…