admin管理员组文章数量:1122832
I am using the latest version of g++, i.e. version 14.2 on Ubuntu 24.04. When I compile, the "Hello World" code, I get some errors. I am new to c++ and I will appreciate a guiding hand. I can rewrite the code to be conform with c++20 and compile it without problem, but I want to try c++23.
Here is the code:
import std;
using namespace std;
int main(){
println("Hello World");
}
Here is how I compile and the errors:
hakiza@VBox:~/cpp/ppp/ch00$ g++ -std=c++2b helloWorld.cpp -o hello
helloWorld.cpp:1:1: error: ‘import’ does not name a type
1 | import std;
| ^~~~~~
helloWorld.cpp:1:1: note: C++20 ‘import’ only available with ‘-fmodules-ts’, which is not yet enabled with ‘-std=c++20’
helloWorld.cpp: In function ‘int main()’:
helloWorld.cpp:5:5: error: ‘println’ was not declared in this scope
5 | println("Hello World");
| ^~~~~~~
Here is the g++ version:
hakiza@VBox:~/cpp/ppp/ch00$ g++ --version
g++ (Ubuntu 14.2.0-4ubuntu2~24.04) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I am using the latest version of g++, i.e. version 14.2 on Ubuntu 24.04. When I compile, the "Hello World" code, I get some errors. I am new to c++ and I will appreciate a guiding hand. I can rewrite the code to be conform with c++20 and compile it without problem, but I want to try c++23.
Here is the code:
import std;
using namespace std;
int main(){
println("Hello World");
}
Here is how I compile and the errors:
hakiza@VBox:~/cpp/ppp/ch00$ g++ -std=c++2b helloWorld.cpp -o hello
helloWorld.cpp:1:1: error: ‘import’ does not name a type
1 | import std;
| ^~~~~~
helloWorld.cpp:1:1: note: C++20 ‘import’ only available with ‘-fmodules-ts’, which is not yet enabled with ‘-std=c++20’
helloWorld.cpp: In function ‘int main()’:
helloWorld.cpp:5:5: error: ‘println’ was not declared in this scope
5 | println("Hello World");
| ^~~~~~~
Here is the g++ version:
hakiza@VBox:~/cpp/ppp/ch00$ g++ --version
g++ (Ubuntu 14.2.0-4ubuntu2~24.04) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Share
Improve this question
asked Nov 22, 2024 at 10:35
ezymanezyman
3271 silver badge12 bronze badges
2
|
1 Answer
Reset to default 0After some googling, I found the answer by @ChrisMM in this post: "GCC's libstdc++ does not support P2465R3 yet, which allows for import std;
". One can get the same answer from compiler_support for c++23.
本文标签: gc23 quotHello Worldquot not compilingStack Overflow
版权声明:本文标题:g++ - c++23 "Hello World" not compiling - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736304500a1932257.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
-fmodules-ts
as the error message suggests? Aside, modules is a C++20 feature, but the support forstd
module is still incomplete last time I checked. If you just want to try out C++23 feature, just#include<print>
and dostd::println(...)
. – Weijun Zhou Commented Nov 22, 2024 at 10:41import std;
, but it seems that is not the case. – ezyman Commented Nov 22, 2024 at 16:49