# MacOS: CMake unable to link C++ library with ObjC++ library

**URL:** <https://discourse.cmake.org/t/macos-cmake-unable-to-link-c-library-with-objc-library/5361>\
**Category:** Code\
**Tags:** os:macos\
**Created:** [April 3, 2022, 4:12pm UTC](https://discourse.cmake.org/t/macos-cmake-unable-to-link-c-library-with-objc-library/5361 "2022-04-03T16:12:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![devojoyti](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/a88e57/32.png) [@devojoyti](https://discourse.cmake.org/u/devojoyti)\
**Post date:** [April 3, 2022, 4:12pm UTC](https://discourse.cmake.org/t/macos-cmake-unable-to-link-c-library-with-objc-library/5361/1 "2022-04-03T16:12:22Z")

</div>

Basically this question here - [objective c - MacOS: CMake unable to link C++ library with ObjC++ library - Stack Overflow](https://stackoverflow.com/questions/71704144/macos-cmake-unable-to-link-c-library-with-objc-library/71724830?noredirect=1#comment126757976_71724830)

I have created a minimalistic C++ library that I want to use in my Xcode project. It has this directory structure -

```auto
library/
 
    - CMakeLists.txt
    - build/ // build files will reside here 
    - iOS.cmake // toolchain file
    - core/
        - CMakeLists.txt
        - squareroot.h
        - squareroot.cpp
    - platform/
        - CMakeLists.txt
        - squrerootwrapper.h
        - squarerootwrapper.mm

```

Project link - [GitHub - devojoyti/CMakeLibrary](https://github.com/devojoyti/CMakeLibrary)

Inside `build/` I am doing -

- `cmake ../ -G Xcode -D CMAKE_TOOLCHAIN_FILE=../iOS.cmake -D IOS_PLATFORM=SIMULATOR`
- `xcodebuild -target install -configuration Debug`

Basically, what is happening, is that I am building two libraries, one inside `core/` which calculates the squareroot of a number, another in `platform/` which is a ObjC wrapper on the C++ squareroot computation library. I am linking the core/ library inside platform/ library.

**Problem:**

Problem is, I am unable to link the library generated inside `core/` , with that of generated inside `platform/` . The code builds just fine, and the library (and the corresponding .h header file) is generated.  
However, if I try to use it in my Xcode, it says this:

 ![image](https://discourse.cmake.org/uploads/default/original/2X/c/c42961b3c0c2cda72e01cab4d64e2de6270d3d91.jpeg)

Clearly, the `core/` library functions are not accessible inside `platform/`

I have also tried using `find_library(CORE NAMES core_lib PATHS ${CMAKE_SOURCE_DIR}/core)` but it returns me -  
`CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: CORE linked by target "pim_ios" in directory /Users/ **** /Work/library/platform `

So it is not able to find the library aswell.

Platform specifications:

- MacOS Big Sur, 11.6.5, 2.3 Ghz i9
- CMake - 3.22.2
- Xcode - 13.2.1
