I’m brand new for C++, and I met the bug bother me for few days and desperatly for the answer:
I’m using macbook pro 2023 (Sonoma 14.5 M3 Max) and VS code. And here is my code:
main.cpp
#include<iostream>
void Log(const char* message);
int main()
{
Log("Hello World");
return 0;
}
Log.cpp
#include<iostream>
void Log(const char* message)
{
std::cout<< message <<std::endl;
}
And
tasks.json
{
"tasks": [
{
"type": "shell",
"label": "shell: C/C++: g++ 生成活动文件",
"command": "/usr/bin/g++",
"args": [
"-g",
"${workspaceFolder}/*.cpp",
"${fileDirname}/*.cpp",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
And when I run it, the error shows:
enter image description here
I tried to type
g++ Log.cpp main.cpp
in terminal, and it works. I saw the a.out build successfully and I can use ./a.out
to get Hello World! successfully.
I also copyed the code into Xcode (macos sonoma 14.5 M3max) and VS (windows). On both of them the code works.
I just don’t understand why I cannot make it work with changing tasks.json.
Thank you very much for answer and it will really help!
Best
I tried to modified the tasks.json with plenty of answer related but none of them works
iastatelynnma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.