Setting up C++ with CLion on Windows and Clang, CMake in WSL Ubuntu

3 weeks ago 16
ARTICLE AD BOX

I wish to develop C++20 apps with Jetbrains CLion IDE on Windows and Clang compiler and build tools on WSL. The <format> header file is not recognized and throws an error -

error: no member named 'format' in namespace 'std'

This is my setup in CLion -

CLion IDE setup build tools

Here the CMake options, directions, build options, environment fields are blank with placeholders

CLion IDE setup Debug

I have also tried setting flags explicitly in the CMake file -

cmake_minimum_required(VERSION 3.28.3) project(cpptut) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # Force Clang to use LLVM's libc++ instead of GNU's libstdc++ add_compile_options(-stdlib=libc++) add_link_options(-stdlib=libc++) endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") add_executable(cpptut main.cpp files.cpp strings.cpp test.cpp) Ubuntu clang version 18.1.3 (1ubuntu1) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin

I also tried running this command:

clang++ -stdlib=libstdc++ -gcc-toolchain=/usr/lib/gcc/x86_64-linux-gnu/18

Any help of rectifying the setup problem is much appreciated

Read Entire Article