I build my JUCE project on ARM Mac with the LLVM toolchain so I can use newer C++ features, since Apple clang lags very far behind.
Things have generally worked great with LLVM 17, but LLVM 18 has been out for quite a while and LLVM 19 is on its way. I’ve been trying to upgrade to LLVM 18 for a very long time, and recently finally figured out how to (mostly) get my JUCE project building with LLVM 18 on ARM Mac. There’s some info about it here: Unable to catch exceptions with clang++ 18.1.5 on macos ARM (try-catch does nothing) · Issue #92121 · llvm/llvm-project · GitHub
For reference, basically I just needed to add this to the correct place in the CMakeLists.txt:
if (CMAKE_SYSTEM_NAME MATCHES "Darwin" AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64"
AND CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18)
link_libraries(/opt/homebrew/opt/llvm/lib/libunwind.dylib)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/opt/homebrew/opt/llvm/lib/c++")
endif ()
This resolves two problems. For some reason in LLVM 18 I needed to start explicitly specifying the lib c++ installed with LLVM. I guess I’ve been using the Apple lib c++ with LLVM 17 and that worked, but it doesn’t work with v18. The second fix (the libunwind piece) is a workaround for subclasses of std::exception not being catche-able (this might be Homebrew bug, which was used to install LLVM, but I’m not sure).
Anyway, I can build JUCE Standalone apps this way now, and everything seems to work as intended. But when I try to build a VST3, I get this error:
ld: Undefined symbols:
std::exception_ptr::__from_native_exception_pointer(void*), referenced from:
std::exception_ptr std::make_exception_ptr[abi:ne180100]<std::__1::future_error>(std::__1::future_error) in libMinimal Plugin Example_SharedCode.a[12](juce_core.mm.o)
___cxa_init_primary_exception, referenced from:
std::exception_ptr std::make_exception_ptr[abi:ne180100]<std::__1::future_error>(std::__1::future_error) in libMinimal Plugin Example_SharedCode.a[12](juce_core.mm.o)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
I am hoping there is a simple thing I can add to CMakeLists.txt to resolve this issue as well, but I have no idea how to figure it out. I’ve been Googling around and I’m not finding any information to help me.
Any ideas?
I’d also be grateful for any advice about how I can learn more about debugging and resolving linker errors like this. This aspect of C++ is still a huge mystery to me and I don’t even know where to begin. Maybe I am just missing a linker flag or link_libraries command? I’m not even sure if it’s an LLVM issue, CMake issue, Homebrew installation issue, etc, so I’m not even sure where to turn besides this JUCE forum to ask for help. Maybe I should just try opening an issue again LLVM in github, but I don’t want to come off as a complete newb who wastes these developers’ time.
I can publish a minimal CMake JUCE project to Github if anyone is willing to dig into this with me.
