Build libc++ without threading support

Hello, I am on platform where threading support is not available so I want to build libc++ wihtout thread support.
I am using following config but it fails with following errors:
Can someone suggest what is correct build config to build libc++ withtout thread support.

cmake -G Ninja ../llvm-project/llvm -DLLVM_ENABLE_PROJECTS="clang" \
 -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
-DLLVM_TARGETS_TO_BUILD="X86;Hexagon" -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DLLVM_BUILD_TOOLS=Off -DLIBCXX_ENABLE_THREADS=Off \
-DLLVM_OPTIMIZED_TABLEGEN=1 \
-DCMAKE_INSTALL_PREFIX=/local/mnt2/workspace/users/vpandya/llvm-install

Errors:

/local/mnt2/workspace/users/vpandya/llvm-project/libcxxabi/src/cxa_guard_impl.h:294:8: error: no type named '__libcpp_mutex_t' in namespace 'std'                                             294 |   std::__libcpp_mutex_t mutex = _LIBCPP_MUTEX_INITIALIZER;      

In file included from /local/mnt2/workspace/users/vpandya/llvm-project/libcxxabi/src/cxa_guard.cpp:15:                                                                                      /local/mnt2/workspace/users/vpandya/llvm-project/libcxxabi/src/cxa_guard_impl.h:640:38: error: variable does not have a constant initializer                                              640 | _LIBCPP_CONSTINIT T GlobalStatic<T>::instance = {};

Okay I am able to resolve errors with following config

cmake -G Ninja ../llvm-project/llvm \
    -DLLVM_ENABLE_PROJECTS="clang" \
    -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
    -DLLVM_TARGETS_TO_BUILD="X86;Hexagon" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_C_COMPILER_LAUNCHER=ccache \
    -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
    -DLLVM_BUILD_TOOLS=Off \
    -DLIBCXX_ENABLE_THREADS=Off \
    -DLIBCXXABI_ENABLE_THREADS=Off \
    -DLIBCXX_HAS_NO_THREADS=On \
    -DCMAKE_INSTALL_PREFIX=/local/mnt2/workspace/users/vpandya/llvm-install

but in my build ir , I could not find _LIBCPP_HAS_NO_THREADS defined in include/c++/v1/__config

so I think its not built without thread support.

_LIBCPP_HAS_NO_THREADS would be defined in __config_site, not __config. That file may be in a separate directory depending on your configuration.

Thanks @philnik I found it under /local/mnt2/workspace/users/vpandya/llvm-install/include/x86_64-unknown-linux-gnu/c++/v1

it has required macro defined.
however, my main motivation is to use this libc++ for hexagon arch so is my libc++ build work with that too? or I need to do cross-compilation ?

For a different target you need to cross-compile libc++. I’m not sure how to do that though.

1 Like