Skip to content

Commit 098eb4b

Browse files
committed
fix(compat.opencv): force Apple SDK libc++ headers on macOS (-nostdinc++)
Previous --no-default-config didn't switch headers: clang finds its bundled LLVM-20 libc++ (<llvm>/include/c++/v1) toolchain-relative, where __hash_memory is unconditional, so deployment-target guards can't help. Add -nostdinc++ and -isystem $SDKROOT/usr/include/c++/v1 to build OpenCV against Apple's availability-guarded libc++ headers; with the 14.0 target pin the guard inlines the hash -> no external std::__1::__hash_memory the system dylib lacks.
1 parent 0392bff commit 098eb4b

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

pkgs/c/compat.opencv.lua

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,18 +233,26 @@ local function _install_impl()
233233
-- the active SDK so <stdio.h>/frameworks resolve. xcrun is present on the
234234
-- runner; the command substitution runs inside the build's bash.
235235
--
236-
-- --no-default-config resolves a libc++ header/dylib SKEW: xim:llvm's
237-
-- clang++.cfg wires ITS OWN LLVM-20 libc++ headers (-isystem <llvm>/include/
238-
-- c++/v1) but links against the SDK's Apple system libc++ dylib. OpenCV's
239-
-- unordered_map<string,…> code (persistence.cpp/logtagmanager.cpp) then
240-
-- emits the LLVM-20 out-of-line std::__1::__hash_memory, which the runner's
241-
-- older Apple libc++ doesn't export -> undefined symbol at the consumer link.
242-
-- Dropping the default config makes clang build OpenCV against the SDK's own
243-
-- (Apple) libc++ headers — matching the dylib everything links — so no
244-
-- newer-than-dylib symbol is emitted. SDKROOT (exported here) still supplies
245-
-- the sysroot, so headers/frameworks resolve without the cfg.
246-
libenv = "export SDKROOT=\"$(xcrun --show-sdk-path)\" "
247-
.. "CFLAGS='--no-default-config' CXXFLAGS='--no-default-config' && "
236+
-- Build OpenCV against the SDK's APPLE libc++ headers, not xim:llvm's
237+
-- bundled LLVM-20 ones. The skew: xim:llvm's clang uses its own LLVM-20
238+
-- libc++ headers (found toolchain-relative at <llvm>/include/c++/v1, even
239+
-- without the cfg's -isystem) where std::__1::__hash_memory is UNCONDITIONAL,
240+
-- but the final link resolves libc++ against the runner's Apple system
241+
-- libc++ dylib, which lacks that symbol -> undefined at the consumer link
242+
-- (OpenCV's unordered_map<string,…> in persistence.cpp/logtagmanager.cpp).
243+
-- --no-default-config drop the cfg's -isystem <llvm libc++> (+ --sysroot;
244+
-- SDKROOT below re-supplies the sysroot),
245+
-- -nostdinc++ drop clang's toolchain-relative libc++ headers,
246+
-- -isystem $SDKROOT/usr/include/c++/v1 use Apple's libc++ headers, which
247+
-- DO carry availability guards; paired with the
248+
-- CMAKE_OSX_DEPLOYMENT_TARGET=14.0 pin (< 14.4, where
249+
-- Apple added out-of-line __hash_memory) the guard
250+
-- selects the inline hash path -> no external symbol.
251+
-- -nostdinc++ is C++-only (CXXFLAGS); C HAL files use the SDK libc as usual.
252+
libenv = "export SDKROOT=\"$(xcrun --show-sdk-path)\" && "
253+
.. "export CFLAGS=\"--no-default-config\" "
254+
.. "CXXFLAGS=\"--no-default-config -nostdinc++ "
255+
.. "-isystem $SDKROOT/usr/include/c++/v1\" && "
248256
else
249257
local glibc_bd = pkginfo.build_dep("glibc")
250258
local gcc_bd = pkginfo.build_dep("gcc")

0 commit comments

Comments
 (0)