<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59774>59774</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Building libc++ with libstdc++ as ABI fails with `No rule to make target 'file-NOTFOUND'`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          hadrabap
      </td>
    </tr>
</table>

<pre>
    Hello friends,

I'm playing around with `libc++` and I got an idea to try it with the `libstdc++` as ABI backend. I've been following the instructions located on the llvm project's site: https://libcxx.llvm.org/BuildingLibcxx.html#using-libsupc-on-linux.

The CMake configuration went smooth without issues but the subsequent `make cxx` failed like this:
```
make[3]: *** No rule to make target 'file-NOTFOUND', needed by 'lib/libc++.so.1.0'.  Stop.
make[2]: *** [CMakeFiles/Makefile2:454: libcxx/src/CMakeFiles/cxx_shared.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:515: libcxx/src/CMakeFiles/cxx.dir/rule] Error 2
make: *** [Makefile:273: cxx] Error 2
```

I went deeper into the build system in order to figure out what is going on and I discovered that "missing file" is in fact `libstdc++.a`, the static version of `libstdc++`. On my system the library exists but is located in GCC's secret location so CMake `find_package`/`find_library` is not able to find it. And this fact is not reported by the build system.

In order to solve this issue I'd been forced to introduce additional search path: `-DCMAKE_PREFIX_PATH='/usr/lib/gcc/x86_64-redhat-linux/8'`.

The complete CMake invocation now looks like this:
```
LD=ldd CXX=clang++ CC=clang cmake ../runtimes \
 -DCMAKE_PREFIX_PATH='/usr/lib/gcc/x86_64-redhat-linux/8' \ # <== This is needed
        -DCMAKE_INSTALL_PREFIX="$( pwd )/install" \
 -DLIBCXX_LIBDIR_SUFFIX=64 \
        -DLLVM_ENABLE_RUNTIMES="libcxx" \
        -DLIBCXX_HERMETIC_STATIC_LIBRARY=Yes \
 -DLIBCXX_CXX_ABI=libstdc++ \
 -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/8/;/usr/include/c++/8/x86_64-redhat-linux" \
        -DLIBCXX_ENABLE_PARALLEL_ALGORITHMS=No \
 -DLIBCXX_ENABLE_SHARED=Yes \
 -DLIBCXX_ENABLE_STATIC=Yes
```

It is nothing crucial but it took me quite a while to figure it out. So maybe some other people would like to know this. The shared `libc++` requires static version of `libstdc++` (which is probably documented somewhere).

My OS is: Oracle Linux 8.7 (based on RHEL 8) with UEK kernel and stock GCC 8.5 and stock clang 14.

```
[opc@sws build-libcxx]$ gcc --version
gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-15.0.2)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[opc@sws build-libcxx]$ clang --version
clang version 14.0.6 (Red Hat 14.0.6-1.0.1.module+el8.7.0+20823+214a699d)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```

The `libc++` in question is from this source tree, tag `tags/llvmorg-15.0.6`.

The CMake debug log looks like this:
```
CMake Debug Log at /home/opc/Desktop/Projects/llvm/llvm-project/libcxx/cmake/Modules/HandleLibCXXABI.cmake:75 (find_library):
  find_library called with the following settings:

 VAR: file
    NAMES: "libstdc++.a"
    Documentation: Path to a library.
    Framework
      Only Search Frameworks: 0
      Search Frameworks Last: 0
      Search Frameworks First: 0
    AppBundle
 Only Search AppBundle: 0
      Search AppBundle Last: 0
      Search AppBundle First: 0
    CMAKE_FIND_USE_CMAKE_PATH: 1
 CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
 CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
 CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
    CMAKE_FIND_USE_INSTALL_PREFIX: 1

  find_library considered the following locations:

 /home/opc/.local/bin//(lib)libstdc++.a(\.so|\.a)
 /home/opc/.local/bin/(lib)libstdc++.a(\.so|\.a)
 /opt/virtualgl/bin//(lib)libstdc++.a(\.so|\.a)
 /opt/virtualgl/bin/(lib)libstdc++.a(\.so|\.a)
 /mnt/nvme/opt/scilab/scilab/bin//(lib)libstdc++.a(\.so|\.a)
 /mnt/nvme/opt/scilab/scilab/bin/(lib)libstdc++.a(\.so|\.a)
 /mnt/nvme/opt/texlive/2022/bin/x86_64-linux//(lib)libstdc++.a(\.so|\.a)
 /mnt/nvme/opt/texlive/2022/bin/x86_64-linux/(lib)libstdc++.a(\.so|\.a)
 /mnt/nvme/opt/java/jdk/bin//(lib)libstdc++.a(\.so|\.a)
 /mnt/nvme/opt/java/jdk/bin/(lib)libstdc++.a(\.so|\.a)
 /mnt/nvme/opt/java-tools/maven/bin//(lib)libstdc++.a(\.so|\.a)
 /mnt/nvme/opt/java-tools/maven/bin/(lib)libstdc++.a(\.so|\.a)
 /mnt/nvme/opt/java-tools/ant/bin//(lib)libstdc++.a(\.so|\.a)
 /mnt/nvme/opt/java-tools/ant/bin/(lib)libstdc++.a(\.so|\.a)
 /mnt/nvme/opt/go/bin//(lib)libstdc++.a(\.so|\.a)
 /mnt/nvme/opt/go/bin/(lib)libstdc++.a(\.so|\.a)
 /mnt/nvme/opt/bin//(lib)libstdc++.a(\.so|\.a)
 /mnt/nvme/opt/bin/(lib)libstdc++.a(\.so|\.a)
 /usr/share/Modules/bin//(lib)libstdc++.a(\.so|\.a)
 /usr/share/Modules/bin/(lib)libstdc++.a(\.so|\.a)
 /usr/lib64/ccache//(lib)libstdc++.a(\.so|\.a)
 /usr/lib64/ccache/(lib)libstdc++.a(\.so|\.a)
 /usr/local/bin//(lib)libstdc++.a(\.so|\.a)
 /usr/local/bin/(lib)libstdc++.a(\.so|\.a)
 /usr/local/sbin//(lib)libstdc++.a(\.so|\.a)
 /usr/local/sbin/(lib)libstdc++.a(\.so|\.a)
 /usr/bin//(lib)libstdc++.a(\.so|\.a)
 /usr/bin/(lib)libstdc++.a(\.so|\.a)
 /usr/sbin//(lib)libstdc++.a(\.so|\.a)
 /usr/sbin/(lib)libstdc++.a(\.so|\.a)
 /home/opc/.local/share/JetBrains/Toolbox/scripts//(lib)libstdc++.a(\.so|\.a)
 /home/opc/.local/share/JetBrains/Toolbox/scripts/(lib)libstdc++.a(\.so|\.a)
 /var/lib/snapd/snap/bin//(lib)libstdc++.a(\.so|\.a)
 /var/lib/snapd/snap/bin/(lib)libstdc++.a(\.so|\.a)
 /usr/local/lib64//(lib)libstdc++.a(\.so|\.a)
 /usr/local/lib64/(lib)libstdc++.a(\.so|\.a)
 /usr/local/lib//(lib)libstdc++.a(\.so|\.a)
 /usr/local/lib/(lib)libstdc++.a(\.so|\.a)
 /usr/local//(lib)libstdc++.a(\.so|\.a)
 /usr/local/(lib)libstdc++.a(\.so|\.a)
 /usr/lib64//(lib)libstdc++.a(\.so|\.a)
 /usr/lib64/(lib)libstdc++.a(\.so|\.a)
 /usr/lib//(lib)libstdc++.a(\.so|\.a)
 /usr/lib/(lib)libstdc++.a(\.so|\.a)
 /usr//(lib)libstdc++.a(\.so|\.a)
 /usr/(lib)libstdc++.a(\.so|\.a)
 /lib64//(lib)libstdc++.a(\.so|\.a)
 /lib64/(lib)libstdc++.a(\.so|\.a)
 /lib//(lib)libstdc++.a(\.so|\.a)
 /lib/(lib)libstdc++.a(\.so|\.a)
 /mnt/nvme/opt/Qt/Tools/CMake//(lib)libstdc++.a(\.so|\.a)
 /mnt/nvme/opt/Qt/Tools/CMake/(lib)libstdc++.a(\.so|\.a)
 /opt//(lib)libstdc++.a(\.so|\.a)
 /opt/(lib)libstdc++.a(\.so|\.a)
 /usr/lib64/X11//(lib)libstdc++.a(\.so|\.a)
 /usr/lib64/X11/(lib)libstdc++.a(\.so|\.a)
 /home/opc/Desktop/Projects/llvm/llvm-project/libcxx//(lib)libstdc++.a(\.so|\.a)
 /home/opc/Desktop/Projects/llvm/llvm-project/libcxx/(lib)libstdc++.a(\.so|\.a)

 The item was not found.

Call Stack (most recent call first):
 /home/opc/Desktop/Projects/llvm/llvm-project/libcxx/cmake/Modules/HandleLibCXXABI.cmake:92 (imported_library)
 /home/opc/Desktop/Projects/llvm/llvm-project/libcxx/CMakeLists.txt:497 (include)
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEWllz4rgW_jXKyylcRmZ9yINZPOEOIblAptJPlGwLWxNh0ZIckn9_S5JNIKG3QN-eyjRgn01n-c6RbKIUywpKr1F7gNqjK1LqXMjrnKSSxGR7FYv09fqGci5gLRktUoXwEPkj5Ifu3wnC3Q1sOXllRQZEirJIYcd0DqjjcxYnCA_MX8cHUqQwgUxoIAWwlBLQArR8BaYdh85pxaV0esioIBxMICbJEy1SD4zOZwoxpQWsBediZ3QbblYoLctEM1Eo4CIhmqYgCnuP8-cNbKX4lyYa4a4CxTRFQQi51luFghDhCOHI2Pzy4hlqT8gM4WhQMp6yIpu6O7necISDUrEiaxhby23SEEWDs6J88Q59s8wpDG_JE4VEFGuWlZIYy2BHCw1qI4TO7cJFqYEpVVIFcamtsaqMFf1aGkLU8TdWxsuLccaaME5T4OyJgs6ZNdzp7PjVn_1peFB7EKD2yCwS4dD9wUyALDk1zrdyNZEZ1YBwd804bczultHdw2yEcBfhIRSUpjSF-NUQcBZXHnLB8ZTwmp6PcNcDWGix9Y504w-6UXtgHRIxThXCkflutGIUhK12yxA7_yMcKZkgHB2RJy8vK5UTSVMvZRLhiHCO2iMYSykk4CPlzV9S3m62f0J5pdW477Ta9_pqFSgIcTcwt43496zvIlcVlkuTlNItlcAKUys5hdgkI6hXpekGWAFCplSaWNr8omByaZcTk1CQCVMXoqgqL2UqEc9U0hS0oUAYb5gyaQzWRowNEytgTRL9oRA9YgzEQ5eemmiWwDOVyiS0WJ-qWw_uCti81sbaGmSxJPIV6AtT2mU7eytUVsBfw6GrTZpIqt0do0GJqpJQx1-zIl1tSfJEMmptiuqLlXhTJkxBYZAmdplubgPTHoRFasvGLbKiknQrpHZp_t7JRxU9O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