Cannot compile import std

191 views Asked by At

Can't make example from book work. I'm using VSCode and G++12. The code is

import std;

int main()
{
    int a{42};
    std::println(a);

    return 0;
}

and the CMakeLists is

cmake_minimum_required(VERSION 3.5)

project(exercises
        VERSION 1.0
        LANGUAGES CXX)
                
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_COMPILER "/usr/bin/g++-12")

add_executable(${PROJECT_NAME} src/main.cpp)
target_compile_options(${PROJECT_NAME} PRIVATE -fmodules-ts -ggdb -Werror -Wall -Wpedantic)

But when I try to compile it I get errors

In module imported at /home/m/programming/c++/exercises/general_exercises/src/main.cpp:1:1:
std: error: failed to read compiled module: No such file or directory
std: note: compiled module file is ‘gcm.cache/std.gcm’
std: note: imports must be built before being imported
std: fatal error: returning to the gate for a mechanical issue
compilation terminated.    

The book gives no information on how to compile given code, so any help will be appreciated.

I've tried to use Clang, but I have no experience with it, so just got some other errors...

0

There are 0 answers