我无法使用可视化工作室代码构建C++
I can't build C++ with visual studio code
我想用C++编译我的"你好世界",但我做不到。我使用Visual Studio代码,这是我的代码。
当我尝试构建cpp时,错误是:
clang:错误:没有这样的文件或目录:"/Users/a1/C++/first">
我的文件是"/Users/a1/C++/first.cpp">
这适用于macOS、High Sierra 10.14和Visual studio代码。
我安装了C/C++,但现在我无法构建我的C++。
#include "stadfx.h"
#include < iostream >
int _tmain(int argc, _TCHAR* argv[]) {
std::cout <<"Hello, World" <<std::endl;
return 0;
}
执行任务:g++/Users/a1/C++/first.cpp-o-g/Users/a1/C++/fist<
clang:error:没有这样的文件或目录:'/Users/a1/C++/first'터미널 프로세스가 종료 코드1(으)로 종료되었습니다.
这是我的"tasks.json">
{
"version": "2.0.0",
"runner": "terminal",
"type": "shell",
"echoCommand": true,
"presentation" : { "reveal": "always" },
"tasks": [
//C++ 컴파일
{
"label": "build and compile for C++",
"type": "shell",
"command": "g++",
"args": [
"${file}",
"-o","-g",
"${fileDirname}/${fileBasenameNoExtension}"
],
"group": {
"kind":"build",
"isDefault": true },
//컴파일시 에러를 편집기에 반영
//참고: https://code.visualstudio.com/docs/editor/tasks#_defining-a-problem-matcher
"problemMatcher": {
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
// The regular expression.
//Example to match: helloWorld.c:5:3: warning: implicit declaration of function 'prinft'
"regexp": "^(.*):(\d+):(\d+):\s+(warning error):\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
},
//C 컴파일
{
"label": "save and compile for C",
"command": "gcc",
"args": [
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"group": {
"kind":"build",
"isDefault": true},
//컴파일시 에러를 편집기에 반영
//참고: https://code.visualstudio.com/docs/editor/tasks#_defining-a-problem-matcher
"problemMatcher": {
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
// The regular expression.
//Example to match: helloWorld.c:5:3: warning: implicit declaration of function 'prinft'
"regexp": "^(.*):(\d+):(\d+):\s+(warning error):\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
},
// 바이너리 실행(Ubuntu)
{
"label": "execute",
"command": "cd ${fileDirname} && ./${fileBasenameNoExtension}",
"group": "test"
}
]
}
这是我的"launch.json">
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.out",
"miDebuggerPath": "/Users/a1/C++/cpp.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb"
}
]}
这是我的"c_cpp_properties.json">
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}"
],
"defines": ["_DEBUG", "UNICODE"],
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/Users/a1/C++/first.cpp",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"browse": {
"path": [
"${workspaceFolder}","/Users/a1/C++/first.cpp"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"version": 4
}
-o选项需要一个文件名,该文件名应紧跟在"-o"之后。您已将"-g"作为文件名。然后命令以一个要编译的文件结束。在你的情况下,"第一"(不存在)。
尝试将json文件中的订单移动到类似以下内容:
"args": [
"-g",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"${file}"
],
相关文章:
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 代码在main()中运行,但在函数中出现错误
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 编译包含字符串的代码时遇到问题
- 我在c++代码中生成了一个运行时#3异常
- 如何在linux终端中同时编译和运行c++代码
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 在Linux for Windows上编译C++代码时出错
- VI工作室代码错误无法打开输出文件主.exe
- 与其他编译器相比,相同的代码在工作室Microsoft提供不同的输出
- 视觉工作室代码远程调试C 类似Netbeans的方式
- 我无法使用可视化工作室代码构建C++
- 显示视觉工作室代码C++时出错
- complex.h 适用于 Win32 目标以外的其他编译器,例如代码编辑器工作室 (CCS)
- 如何停止任务运行终端在程序以视觉工作室代码结束后自动退出
- 代码编辑器工作室 for Arm 中类的 C++ 编译错误
- 当从视觉工作室中的 IDL 文件生成 CPP 代码时,如何删除属性"in"的"const"?
- 是否有可能改变.so文件代码在android工作室本身,并使构建
- 代码编写器工作室中的取消引用指针
- 视觉工作室 - 无法"ldap_bind_s" AD C++(0x31错误代码)