【发布时间】:2022-06-18 05:55:13
【问题描述】:
我正在尝试关注this link,了解如何在 ubuntu 中开始使用 c++ 和 vscode。
我已经安装了最新版本的 gcc。
运行sudo apt-get install build-essential gdb 给出:
Reading package lists... Done
Building dependency tree
Reading state information... Done
build-essential is already the newest version (12.8ubuntu1.1).
build-essential set to manually installed.
gdb is already the newest version (9.2-0ubuntu1~20.04.1).
gdb set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
但是,当我进入创建配置文件的阶段时,我没有选择C/C++: g++ build active file。我只有
所以,我选择 /usr/bin/cpp。然后我构建文件,并获得成功消息。 但是,当运行新创建的可执行文件时,我收到了几条错误消息:
./helloworld: line 17: namespace: command not found
./helloworld: line 23: syntax error near unexpected token `('
./helloworld: line 23: ` typedef decltype(nullptr) nullptr_t;'
奇怪的是helloworld文件中的代码行在第16行结束,所以我认为编译器有问题......
【问题讨论】:
-
老实说,我总是发现在 Windows 以外的平台上编译时使用 Cmake 或 makefile 更容易。
-
怀疑编译器有问题,更有可能是vs代码构建系统有问题。我想如果你在命令行上编译它会工作得很好。
-
@Taekahn 你是对的......我只是从教程中复制了 tasks.json,并覆盖了以前的版本。然后我运行了可执行文件,它工作了。
标签: c++ ubuntu visual-studio-code