# building macOS CMake based project lacks backward compatibility

**URL:** https://discourse.cmake.org/t/building-macos-cmake-based-project-lacks-backward-compatibility/6381
**Category:** Usage
**Tags:** gen:xcode
**Created:** [September 1, 2022, 9:07am UTC](https://discourse.cmake.org/t/building-macos-cmake-based-project-lacks-backward-compatibility/6381 "2022-09-01T09:07:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zohar81](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zohar81/32/2252_2.png) [@zohar81](https://discourse.cmake.org/u/zohar81)
#### Post date: [September 1, 2022, 9:07am UTC](https://discourse.cmake.org/t/building-macos-cmake-based-project-lacks-backward-compatibility/6381/1 "2022-09-01T09:07:15Z")

</div>

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 :

```auto
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

```auto
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.

---

<div class="post-metadata">

### Author: ![klirichek](https://discourse.cmake.org/user_avatar/discourse.cmake.org/klirichek/32/1657_2.png) [@klirichek](https://discourse.cmake.org/u/klirichek)
#### Post date: [September 5, 2022, 12:54pm UTC](https://discourse.cmake.org/t/building-macos-cmake-based-project-lacks-backward-compatibility/6381/2 "2022-09-05T12:54:37Z")

</div>

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.

```auto
# 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}" )

```
