c++ - 在 Ubuntu 上的 VS 代码上运行 C++ 代码并收到此错误 collect2: error: ld returned 1 exit status
问题描述
我是 VS 代码的新手,我正在尝试运行基本的 C++ 代码:
#include<iostream>
using namespace std;
int main(){
cout<<"Hello World";
return 0;
}
我收到此错误:未定义对“main”collect2 的引用:错误:ld 返回 1 退出状态
解决方案
我添加了此任务配置,它工作正常:
`
{"version": "2.0.0",
"tasks": [
{
"label": "debug",
"type": "shell",
"command": "",
"args": ["g++","-g", "${relativeFile}", "-o","a.exe"]
},
{
"label": "Compile and run",
"type": "shell",
"command": "",
"args": [
"g++","-g", "${relativeFile}", "-o","${fileBasenameNoExtension}.out", "&&", "clear" , "&&" , "./${fileBasenameNoExtension}.out"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
},
]}
`
推荐阅读
- javascript - 了解如何更改 SVG
- sql - 选择具有一个 unique_id 和第二个 unique_id 不同 ORACLE 的重复行
- sql-server - 如何根据字段条件对结果进行 SQL PIVOT 格式化?
- swift - reverseValueTransformed 改变有界属性后如何调用 valueTransformed?(迅速)
- json - 尝试使用 JSON 加载时出错。相信字符串格式正确
- git - 如何为拉取请求恢复已删除的分叉分支
- reactjs - 此代码是表示组件/容器组件结构的示例吗?
- php - 带有python脚本“退出代码:127(找不到命令)”的Laravel任务计划
- vue.js - How to center the text on vuetify footer?
- c - Printing struct to a file printing all empty elements of a char array