Errors [unknown type name 'import'], etc.
-
wrote on 29 Jan 2025, 10:37 last edited by
Hello!
Environment
- Mac Mini M4;
- Sequoia 15.3;
- Commands Tools installed thanks to xcode-select --install command.
- Qt Creator 15.0.1. Based on Qt 6.8.1 (Clang 15.0 (Apple), arm64)
clang --version
The “clang --version” command displays :
Apple clang version 16.0.0 (clang-1600.0.26.6)
Target: arm64-apple-darwin24.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/binxcode-select -print-path displays
/Library/Developer/CommandLineToolsNote: whether Xcode is fully installed or not, doesn't solve the problem.
The program
This first program, which is supposed to use C++23, displays the following error:
import std; int main() { std::println(“Hello”); }
CMakeLists.txt
CMakeLists.txt has been defined as follows:
cmake_minimum_required(VERSION 3.16) project(CPPBasic LANGUAGES CXX) set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_executable(CPPBasic main.cpp)
Errors displayed
error: unknown type name 'import' error: 'std' is not a class, namespace, or enumeration error: Module 'std' not found
My question
What is the solution for using C++23?
(Book : Beginning C++23 by I. Horton)Thanks for your help.
-
Hello!
Environment
- Mac Mini M4;
- Sequoia 15.3;
- Commands Tools installed thanks to xcode-select --install command.
- Qt Creator 15.0.1. Based on Qt 6.8.1 (Clang 15.0 (Apple), arm64)
clang --version
The “clang --version” command displays :
Apple clang version 16.0.0 (clang-1600.0.26.6)
Target: arm64-apple-darwin24.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/binxcode-select -print-path displays
/Library/Developer/CommandLineToolsNote: whether Xcode is fully installed or not, doesn't solve the problem.
The program
This first program, which is supposed to use C++23, displays the following error:
import std; int main() { std::println(“Hello”); }
CMakeLists.txt
CMakeLists.txt has been defined as follows:
cmake_minimum_required(VERSION 3.16) project(CPPBasic LANGUAGES CXX) set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_executable(CPPBasic main.cpp)
Errors displayed
error: unknown type name 'import' error: 'std' is not a class, namespace, or enumeration error: Module 'std' not found
My question
What is the solution for using C++23?
(Book : Beginning C++23 by I. Horton)Thanks for your help.
@Frenchy Do you get these error when you compile your application?
-
Hello!
Environment
- Mac Mini M4;
- Sequoia 15.3;
- Commands Tools installed thanks to xcode-select --install command.
- Qt Creator 15.0.1. Based on Qt 6.8.1 (Clang 15.0 (Apple), arm64)
clang --version
The “clang --version” command displays :
Apple clang version 16.0.0 (clang-1600.0.26.6)
Target: arm64-apple-darwin24.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/binxcode-select -print-path displays
/Library/Developer/CommandLineToolsNote: whether Xcode is fully installed or not, doesn't solve the problem.
The program
This first program, which is supposed to use C++23, displays the following error:
import std; int main() { std::println(“Hello”); }
CMakeLists.txt
CMakeLists.txt has been defined as follows:
cmake_minimum_required(VERSION 3.16) project(CPPBasic LANGUAGES CXX) set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_executable(CPPBasic main.cpp)
Errors displayed
error: unknown type name 'import' error: 'std' is not a class, namespace, or enumeration error: Module 'std' not found
My question
What is the solution for using C++23?
(Book : Beginning C++23 by I. Horton)Thanks for your help.
wrote on 29 Jan 2025, 12:47 last edited by@Frenchy said in Errors [unknown type name 'import'], etc.:
cmake_minimum_required(VERSION 3.16)
What's your CMake version?
CMake 3.16 is not fulfilling the requirements for C++23 Modules.Also, there is a related topic here
-
wrote on 29 Jan 2025, 15:31 last edited by Frenchy
@jsulm - Do you get these error when you compile your application?
Immediately upon code entry for “Module ‘std’ not found”.
Other messages, after compiling.@Pl45m4 - What's your CMake version?
Although I searched the web, I couldn't find a way to determine the current version of Cmake.
I'll take a look at your link.Supplementary question
On Qt Creator version 15, what is the maximum C++ version that can be used?
Thanks to both of you.
-
@jsulm - Do you get these error when you compile your application?
Immediately upon code entry for “Module ‘std’ not found”.
Other messages, after compiling.@Pl45m4 - What's your CMake version?
Although I searched the web, I couldn't find a way to determine the current version of Cmake.
I'll take a look at your link.Supplementary question
On Qt Creator version 15, what is the maximum C++ version that can be used?
Thanks to both of you.
wrote on 29 Jan 2025, 16:03 last edited by Pl45m4@Frenchy said in Errors [unknown type name 'import'], etc.:
I couldn't find a way to determine the current version of Cmake.
Make it
cmake_minimum_required(VERSION 3.30)
and try to configure + build.
You didn't mention your Qt version that you are using.
(QtCreator 15.0.1 does not say anything about the installed version of the Qt Framework. It's just an IDE that was built with 6.8.1 itself) -
Hi,
From the looks of it standard library modules are not supported by Apple's clang.
-
@jsulm - Do you get these error when you compile your application?
Immediately upon code entry for “Module ‘std’ not found”.
Other messages, after compiling.@Pl45m4 - What's your CMake version?
Although I searched the web, I couldn't find a way to determine the current version of Cmake.
I'll take a look at your link.Supplementary question
On Qt Creator version 15, what is the maximum C++ version that can be used?
Thanks to both of you.
wrote on 30 Jan 2025, 00:22 last edited by@Frenchy said in Errors [unknown type name 'import'], etc.:
On Qt Creator version 15, what is the maximum C++ version that can be used?
Qt Creator is an IDE. All it does is simplify running a build process for you. Any limitation comes from the toolchain and libraries you have asked Creator to build your program with. So, the answer is, any version your compiler supports and for which CMake can generate a build process. If you are willing to write your own Makefile then you are not restricted by CMake either.
As @SGaist points out, Apple's Clang 16 does not support standard library modules.
CMake did not introduceCXX_STANDARD 23
until version 3.20. That would be the earliest version you could expect to even attempt to work; but it can only work if the underlying compilers also have support.
In this particular example program there is no involvement of Qt libraries at all. -
wrote on 30 Jan 2025, 10:59 last edited by
Thank you all for your precise and relevant answers.
Best regards. -
3/9