building macOS CMake based project lacks backward compatibility

I’ve got a CMake based project (called myLib.dylib) that that compiles in MacOS Monterey and produces an application and its dependency dynamic library (dylib file)

since the project include some swift file, I generate it for Xcode using this flag : “-G Xcode”
The project pass complication, however there’s a runtime error when trying to run it macOS bigger :

dyld: Symbol not found: __ZTTNSt3__119basic_ostringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE
 Referenced from: /Applications/myapp.app/Contents/MacOS/../Frameworks/libMylib.dylib
 Expected in: /usr/lib/libc++.1.dylib
 in /Applications/myapp.app/Contents/MacOS/../Frameworks/libMylib.dylib
Abort trap: 6

even tough I specifically used the following settings when building the library

set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "Minimum OS X deployment version" FORCE)

Perhaps anybody encountered similar behavior ? the only thing that’s works for my is to build the target in BigSur machine.

Just to be clear: CMAKE_OSX_DEPLOYMENT_TARGET should be set before ‘project’ statement, otherwise it may not work.

I use this toolchain for building our app; that allow cross-compile on any system with clang-13, even on the same host mac OS as target one.

# Generic OSX (Mac OS) toolchain
set ( root /sysroot/root )

# OpenSSL is CASK, need to be provided explicitly
# (path is relative to ${root})
set ( ssldir /opt/openssl )

set ( arch $ENV{arch} )
set ( LLVM /usr/lib/llvm-13 )

set ( CMAKE_SYSTEM_NAME "Darwin" )
set ( CMAKE_SYSTEM_PROCESSOR "${arch}" )

set ( OSX_TRIPLE "${arch}-apple-darwin20.6.0" )
set ( CMAKE_SYSROOT "${root}/MacOSX11.3.sdk" )
set ( CMAKE_OSX_SYSROOT "${CMAKE_SYSROOT}" )
set ( CMAKE_OSX_DEPLOYMENT_TARGET "11.6" )

# where is the target environment
set ( CMAKE_FIND_ROOT_PATH "${CMAKE_SYSROOT}" "${root}" )

# cross compiler
set ( CMAKE_C_COMPILER "${LLVM}/bin/clang" )
set ( CMAKE_CXX_COMPILER "${LLVM}/bin/clang++" )
set ( CMAKE_AR "${LLVM}/bin/llvm-ar" )
set ( CMAKE_RANLIB "${LLVM}/bin/llvm-ranlib" )
set ( CMAKE_INSTALL_NAME_TOOL "${LLVM}/bin/llvm-install-name-tool" )

set ( CMAKE_C_COMPILER_TARGET ${OSX_TRIPLE} )
set ( CMAKE_CXX_COMPILER_TARGET ${OSX_TRIPLE} )
set ( CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=lld" )
set ( CMAKE_MODULE_LINKER_FLAGS_INIT "-fuse-ld=lld" )
set ( CMAKE_SHARED_LINKER_FLAGS_INIT "-fuse-ld=lld" )

# search for programs in the build host directories
set ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )

# for libraries and headers in the target directories
set ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
set ( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )

set ( CMAKE_CXX_FLAGS_INIT "-stdlib=libc++" )

# this allows pkg-config to correctly find packages
set ( ENV{PKG_CONFIG_PATH} "" )
set ( ENV{PKG_CONFIG_LIBDIR} "${root}/lib/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig" )
set ( ENV{PKG_CONFIG_SYSROOT_DIR} "${CMAKE_SYSROOT}" )

set ( ENV{OPENSSL_ROOT_DIR} "${ssldir}" )