NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own!
{
"name": "use-stdlib-libc++",
"description": "Enforce to compile and link with libc++",
"hidden": true,
"cacheVariables": {
"CXX": "clang++",
"CMAKE_CXX_FLAGS": "-stdlib=libc++",
"CMAKE_EXE_LINKER_FLAGS": "-stdlib=libc++",
"CMAKE_SHARED_LINKER_FLAGS": "-stdlib=libc++"
}
},
and use it by inheritance
Check the output of CMake:
[cmake] -- The CXX compiler identification is Clang 14.0.0
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - failed
[cmake] -- Check for working CXX compiler: /usr/bin/clang++
[cmake] -- Check for working CXX compiler: /usr/bin/clang++ - broken
[cmake] CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
[cmake] The C++ compiler
[cmake]
[cmake] "/usr/bin/clang++"
[cmake]
[cmake] is not able to compile a simple test program.
[cmake]
[cmake] It fails with the following output:
[cmake]
[cmake] Change Dir: /workspaces/playground/build/linux-clang-libc++-release/CMakeFiles/CMakeTmp
[cmake]
[cmake] Run Build Command(s):/usr/bin/ninja cmTC_f5bde && [1/2 (0.024s)] Building CXX object CMakeFiles/cmTC_f5bde.dir/testCXXCompiler.cxx.o
[cmake] [2/2 (0.050s)] Linking CXX executable cmTC_f5bde
[cmake] FAILED: cmTC_f5bde
[cmake] : && /usr/bin/clang++ -stdlib=libc++ -stdlib=libc++ CMakeFiles/cmTC_f5bde.dir/testCXXCompiler.cxx.o -o cmTC_f5bde && :
[cmake] /usr/bin/ld: cannot find -lc++abi: No such file or directory
Recognize not able to compile due to cannot find -lc++abi
Check installed libc++ libs:
$ ll /usr/lib/llvm-14/lib/libc++*
-rw-r--r-- 1 root root 2983660 Mar 24 13:24 /usr/lib/llvm-14/lib/libc++.a
lrwxrwxrwx 1 root root 16 Mar 24 13:24 /usr/lib/llvm-14/lib/libc++abi.so.1 -> libc++abi.so.1.0
-rw-r--r-- 1 root root 215736 Mar 24 13:24 /usr/lib/llvm-14/lib/libc++abi.so.1.0
-rw-r--r-- 1 root root 14470 Mar 24 13:24 /usr/lib/llvm-14/lib/libc++experimental.a
-rw-r--r-- 1 root root 37 Mar 24 13:24 /usr/lib/llvm-14/lib/libc++.so
lrwxrwxrwx 1 root root 13 Mar 24 13:24 /usr/lib/llvm-14/lib/libc++.so.1 -> libc++.so.1.0
-rw-r--r-- 1 root root 970688 Mar 24 13:24 /usr/lib/llvm-14/lib/libc++.so.1.0
and notice the missing static lib of libc++abi
Check the packages available for the container:
$ sudo apt-cache search libc|grep libc++
libc++-14-dev - LLVM C++ Standard library (development files)
libc++1-14 - LLVM C++ Standard library
libc++abi1-14 - LLVM low level support for a standard C++ library
Check the packages inside "real" Ubuntu 22.04 installation, e.g. WSL:
❯ sudo apt-cache search libc|grep libc++ | grep 14
libc++-14-dev - LLVM C++ Standard library (development files)
libc++1-14 - LLVM C++ Standard library
libc++abi-14-dev - LLVM low level support for a standard C++ library (development files)
libc++abi1-14 - LLVM low level support for a standard C++ library
Notice the difference, or even the missing libc++abi-14-dev
Steps to Reproduce:
Create a devcontainer with
Add to your CMakePresets.json
and use it by inheritance
Check the output of CMake:
Recognize
not able to compile
due tocannot find -lc++abi
and notice the missing static lib of libc++abi
libc++abi-14-dev
See e.g. libc++abi-14-dev_14.0.0-1ubuntu1_amd64.deb at 'Files' section
So finally, please add the missing package to your repository so that can be installed inside the deconatiner.