CMake for dynamic linked library AND lib, minor issue

Thanks for that fix and sample code. Now I’m trying to add VST2 support and might be facing a similar issue as before. I was able to use target_include_directories with a path to a directory holding the VST2 SDK. So my DLL/lib are built, and there’s no error about #include <pluginterfaces/vst2.x/aeffect.h>.

Next I have a C++ project that links to the lib but it has unresolved external symbols. This project worked fine before trying to add VST2 support. What could have gone wrong in building the lib, or maybe something is missing a preprocessor definition? I’m using
add_compile_definitions(JUCE_DLL_BUILD=1) add_compile_definitions(JUCE_STANDALONE_APPLICATION=1)

Concise list of missing symbols:

  • “const juce::AudioProcessor::`vftable’” (??_7AudioProcessor@juce@@6B@)
  • “public: static class juce::ModifierKeys juce::ModifierKeys::currentModifiers” (?currentModifiers@ModifierKeys@juce@@2V12@A)
  • “public: static struct juce::SingletonHolder<class juce::ContentSharer,class juce::CriticalSection,0> juce::ContentSharer::singletonHolder”
  • “private: static class juce::JUCEApplicationBase * juce::JUCEApplicationBase::appInstance” (?appInstance@JUCEApplicationBase@juce@@0PEAV12@EA)
  • “public: __cdecl juce::ResizableBorderComponent::Zone::Zone(class juce::ResizableBorderComponent::Zone const &)”
  • "public: static struct juce::SingletonHolder<class juce::ModalComponentManager,class juce::DummyCriticalSection,0>
  • “public: static class juce::JUCEApplicationBase * (__cdecl* juce::JUCEApplicationBase::createInstance)(void)”
  • "public: static struct juce::SingletonHolder<class juce::PushNotifications,class juce::CriticalSection,0>
  • “const juce::GenericAudioProcessorEditor::`vftable’” (??_7GenericAudioProcessorEditor@juce@@6B@)
all missing symbols

1>------ Build started: Project: TD-JUCE-Reverb, Configuration: Release x64 ------
1> Creating library C:/TD-JUCE/Release/TD-JUCE-Reverb.lib and object C:/TD-JUCE/Release/TD-JUCE-Reverb.exp
1>TD-JUCE-Reverb.obj : error LNK2001: unresolved external symbol “const juce::AudioProcessor::vftable'" (??_7AudioProcessor@juce@@6B@) 1>TD-JUCE-Reverb.obj : error LNK2001: unresolved external symbol "public: static class juce::ModifierKeys juce::ModifierKeys::currentModifiers" (?currentModifiers@ModifierKeys@juce@@2V12@A) 1>TD-JUCE-Reverb.obj : error LNK2001: unresolved external symbol "public: static struct juce::SingletonHolder<class juce::ContentSharer,class juce::CriticalSection,0> juce::ContentSharer::singletonHolder" (?singletonHolder@ContentSharer@juce@@2U?$SingletonHolder@VContentSharer@juce@@VCriticalSection@2@$0A@@2@A) 1>TD-JUCE-Reverb.obj : error LNK2001: unresolved external symbol "private: static class juce::JUCEApplicationBase * juce::JUCEApplicationBase::appInstance" (?appInstance@JUCEApplicationBase@juce@@0PEAV12@EA) 1>TD-JUCE-Reverb.obj : error LNK2001: unresolved external symbol "public: __cdecl juce::ResizableBorderComponent::Zone::Zone(class juce::ResizableBorderComponent::Zone const &)" (??0Zone@ResizableBorderComponent@juce@@QEAA@AEBV012@@Z) 1>TD-JUCE-Reverb.obj : error LNK2001: unresolved external symbol "public: static struct juce::SingletonHolder<class juce::ModalComponentManager,class juce::DummyCriticalSection,0> juce::ModalComponentManager::singletonHolder" (?singletonHolder@ModalComponentManager@juce@@2U?$SingletonHolder@VModalComponentManager@juce@@VDummyCriticalSection@2@$0A@@2@A) 1>TD-JUCE-Reverb.obj : error LNK2001: unresolved external symbol "public: static class juce::JUCEApplicationBase * (__cdecl* juce::JUCEApplicationBase::createInstance)(void)" (?createInstance@JUCEApplicationBase@juce@@2P6APEAV12@XZEA) 1>TD-JUCE-Reverb.obj : error LNK2001: unresolved external symbol "public: static struct juce::SingletonHolder<class juce::PushNotifications,class juce::CriticalSection,0> juce::PushNotifications::singletonHolder" (?singletonHolder@PushNotifications@juce@@2U?$SingletonHolder@VPushNotifications@juce@@VCriticalSection@2@$0A@@2@A) 1>TD-JUCE-Reverb.obj : error LNK2001: unresolved external symbol "const juce::GenericAudioProcessorEditor::vftable’” (??_7GenericAudioProcessorEditor@juce@@6B@)
1>C:\TD-JUCE\Release\TD-JUCE-Reverb.dll : fatal error LNK1120: 9 unresolved externals

P.S. If that seems like a dead-end, I would happily take more advice about CMake. I’m trying to use the code you provided but am having trouble fitting it in the context of this page https://github.com/juce-framework/JUCE/blob/master/docs/CMake%20API.md and https://github.com/juce-framework/JUCE/blob/master/examples/CMake/AudioPlugin/CMakeLists.txt

For context my project’s folder is C:/TD-JUCE.

I do this in CMD:
cd C:\TD-JUCE\thirdparty\JUCE_6
cmake -B cmake-build-install -DCMAKE_INSTALL_PREFIX=C:\TD-JUCE\thirdparty\JUCE_6\my_install
Then build:
cmake --build cmake-build-install --target install

Then in my main C:\TD-JUCE\CMakeLists.txt:

project(TD-JUCE VERSION 0.0.1)
# add_subdirectory(${PROJECT_SOURCE_DIR}/thirdparty/JUCE_6) # choosing find_package instead
find_package(JUCE CONFIG REQUIRED)  
add_library(TD-JUCE SHARED)
# then code you shared replacing my_juce_dll with TD-JUCE

Then in C:/TD-JUCE/build:
cmake -DCMAKE_PREFIX_PATH=C:/TD-JUCE/thirdparty/JUCE_6/my_install ..

Then I get variations of an error discussed on the forums (Learning CMake done right with JUCE 6).

CMake Error at CMakeLists.txt:105 (add_library): Target "TD-JUCE" links to target "juce::audio_basics" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?

Thanks!