<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/73248>73248</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[OpenMP] build error: undefined reference to `std::__glibcxx_assert_fail`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tgymnich
</td>
</tr>
</table>
<pre>
[Enabling libstdc++ assertions](https://reviews.llvm.org/D142279) (`-D_GLIBCXX_ASSERTIONS`) introduces an unwanted dependency on libstdc++ for libomp. This causes a linker error when building libomp with assertions enabled (`-DLLVM_ENABLE_ASSERTIONS=ON`).
### Build error:
```
[45/71] Linking C shared library openmp/runtime/src/libomp.so
FAILED: openmp/runtime/src/libomp.so
: && /tmp/llvm-project/build/./bin/clang --target=x86_64-unknown-linux-gnu -fPIC -fPIC -fno-semantic-interposition -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -Wall -Wcast-qual -Wformat-pedantic -Wimplicit-fallthrough -Wsign-compare -Wno-enum-constexpr-conversion -Wno-extra -Wno-pedantic -g -Wl,-z,defs -Wl,-z,nodelete -fuse-ld=gold -Wl,--gdb-index -Wl,--as-needed -Wl,--version-script=/tmp/llvm-project/openmp/runtime/src/exports_so.txt -static-libgcc -Wl,-z,noexecstack -shared -Wl,-soname,libomp.so -o openmp/runtime/src/libomp.so openmp/runtime/src/CMakeFiles/omp.dir/kmp_alloc.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_atomic.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_csupport.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_debug.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_itt.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_environment.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_error.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_global.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_i18n.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_io.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_runtime.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_settings.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_str.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_tasking.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_threadprivate.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_utility.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_barrier.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_wait_release.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_affinity.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_dispatch.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_lock.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_sched.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_collapse.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/z_Linux_util.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_gsupport.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/thirdparty/ittnotify/ittnotify_static.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_taskdeps.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_cancel.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_cdecl.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_extra.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_version.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/ompt-general.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/ompd-specific.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/z_Linux_asm.S.o -lm -ldl && cd /tmp/llvm-project/build/runtimes/runtimes-bins/openmp/runtime/src && /usr/bin/cmake -E create_symlink libomp.so libgomp.so && /usr/bin/cmake -E create_symlink libomp.so libiomp5.so
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/atomic_base.h:485: error: undefined reference to 'std::__glibcxx_assert_fail(char const*, int, char const*, char const*)'
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/atomic_base.h:486: error: undefined reference to 'std::__glibcxx_assert_fail(char const*, int, char const*, char const*)'
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/atomic_base.h:485: error: undefined reference to 'std::__glibcxx_assert_fail(char const*, int, char const*, char const*)'
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/atomic_base.h:486: error: undefined reference to 'std::__glibcxx_assert_fail(char const*, int, char const*, char const*)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
### How To Reproduce:
The issue started appearing with libstdc++ >= 12.
[Here](https://gist.github.com/tgymnich/aaaad86dd351166df3aceb056e7399ee) is a Dockerfile to reproduce the issue.
### Related issues:
- https://github.com/llvm/llvm-project/issues/71805
- https://reviews.llvm.org/D143168
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWF1v2zoS_TX0C0HDomzZfvCDE8d7C6TtRVts7ptBkSNp1hSpJSnb6a9fUJadpE3QInrYBfYChqwPzuE5w-HHjPAeSwOwIrMbMtuMRBsq61ahfKwNymqUW_UYv90ZkWs0JdWY-6Ak4TeE31DhPbiA1ngy2xC-qEJoPEnXhG8J3zo4IBz9WOtDPbauJHy7Saacz5eELynhC5JN2Gb3j_sPN7d__bVbf_169-Xbh8-fvpJsElugCc6qVoKnwtDWHIUJoKiCBowCIx-pNT8QKqyLb2zdjOm3Cj2VovXRnmo0e3AU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