# detecting if libc++ is present

**URL:** https://discourse.cmake.org/t/detecting-if-libc-is-present/9006
**Category:** Usage
**Created:** [September 19, 2023, 8:05am UTC](https://discourse.cmake.org/t/detecting-if-libc-is-present/9006 "2023-09-19T08:05:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [September 19, 2023, 8:05am UTC](https://discourse.cmake.org/t/detecting-if-libc-is-present/9006/1 "2023-09-19T08:05:03Z")

</div>

I wanted to automatically set `stdlib` to `libc++` when compiler is `clang` but I stumbled upon a machine where `clang++` was present but

```cmake
target_link_options(${TARGET_NAME} PUBLIC $<$<LINK_LANGUAGE:CXX>:-stdlib=libc++>) 

```

emitted an error.  
Thus I suppose that `libc++` is not necessarily installed along clang++.

What would be the simplest way to test if `libc++` can be used ?

Thanks in advance, Regards  
A.  
Addendum: It seems that certain configurations also require `-lc++abi`, how can I detect that?

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [September 19, 2023, 11:31am UTC](https://discourse.cmake.org/t/detecting-if-libc-is-present/9006/2 "2023-09-19T11:31:09Z")

</div>

I haven’t tried your case to see if there’s a straightforward way with find\_library. However, in general when I need to test something that is easiest to do from a small project, I make a subdirectory and put a simple CMakeLists.txt. I then test that project at CMake configure time using try\_compile from the main project.

> <https://github.com/scivision/fortran-filesystem/blob/37316e31b6d86843aed3219ae0dc15dd49024003/cmake/compilers.cmake#L84>

Example where the fs\_check directory is used via try\_compile to ensure that c++ standard library filesystem is linkable and actually working. Because the feature check macros don’t always ensure that the standard library works for that particular case.

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [September 19, 2023, 3:15pm UTC](https://discourse.cmake.org/t/detecting-if-libc-is-present/9006/3 "2023-09-19T15:15:59Z")

</div>

Thanks, it’s an idea but I’m afraid of the time overhead when reconfiguring the projects. I expected some more straightforward technic.  
A.
