How to setup VS Code for Building, Running and Debugging simple C++ files in OSX?









up vote
0
down vote

favorite












The closest similar answer I found for it is here



But that doesn't contain an answer to my question. I also went through the docs for trying to have C++ support to VSCode. I didn't find OSX specific settings and I am not well versed with such configurations. Could someone please help
?



Update:



Adding the contents of tasks.json, launch.json, c_cpp_properties.json, and terminal output for more clarity:



tasks.json:




"version": "2.0.0",
"tasks": [

"label": "build & debug file",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-o",
"$fileBasenameNoExtension",
"$file"
],
"group":
"kind": "build",
"isDefault": true

,

"label": "build & run file",
"type": "shell",
"command": "g++",
"args": [
"-o",
"$fileBasenameNoExtension",
"$file"
],
"group":
"kind": "build",
"isDefault": true
,
"problemMatcher":

]




launch.json:




// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "$workspaceFolder/test",
"args": ,
"stopAtEntry": false,
"cwd": "$workspaceFolder",
"environment": ,
"externalConsole": true,
"MIMode": "lldb"

]




c_cpp_properties.json:




"configurations": [

"name": "Mac",
"includePath": [
"$workspaceFolder/**",
"/usr/local/Cellar/gcc/7.1.0/include/c++/7.1.0",
"/usr/include/c++/4.2.1"
],
"defines": ,
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"

],
"version": 4


Current problem I am facing with this configuration is that I get the following error when I try: Terminal-> Run Build Task-> build & debug file:



 ld: warning: ignoring file /Users/xyz/Workspace/VSCode/.vscode/tasks.json, file was built for unsupported file format ( 0x7B 0x0A 0x20 0x20 0x20 0x20 0x22 0x76 0x65 0x72 0x73 0x69 0x6F 0x6E 0x22 0x3A ) which is not the architecture being linked (x86_64): /Users/xyz/Workspace/VSCode/.vscode/tasks.json
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The terminal process terminated with exit code: 1









share|improve this question























  • You should first be able to build from command line, using 'any editor'. If you have this, show your build process (edit the question). If not, start with that before tackling VS Code (or any "non-IDE" programmers editor) integration.
    – hyde
    Nov 9 at 20:24











  • @hyde I am able to build Cpp code from other editors such as Sublime Text and also debug them using CodeLite IDE. But it appears that we need to setup configs for the same in VSCode, specifically in the tasks.json, c_cpp_properties.json and launch.json. I don't know what to include in these files and am getting different errors while trying values from different sources for the aforementioned jsons. So, if you or anyone could provide the contents of the files, for an easy setup on Mac, it would be great.
    – user3760100
    Nov 10 at 9:20










  • Yeah, the thing is, there are dozens of ways to build C++ projects, with several layers of tools. Without knowing uour build process it is impossible to help. If you can get compile output view (as text, copy-paste) from some of these, it probably would help a lot here.
    – hyde
    Nov 10 at 9:49










  • @hyde, could you please tell me how to obtain info about my build process so that I can paste it here? I just remember installing xcode. I don't remember explicitly setting any build process for sublime, etc. Or rather, if the only 3 things I want from VS Code is 1) Intellisense code completion, 2) Ability to run a simple C++ file 3) Ability to debug a simple C++ file, what configurations should I mention in the config files above?
    – user3760100
    Nov 10 at 18:52










  • Your linker error hints at an options mismatch, are you compiler for x86, or other, and linking for x64? You look like you’ve got the build tools from homebrew, so it wouldn’t be obvious what the defaults that you have are.
    – Niall
    Nov 10 at 20:03














up vote
0
down vote

favorite












The closest similar answer I found for it is here



But that doesn't contain an answer to my question. I also went through the docs for trying to have C++ support to VSCode. I didn't find OSX specific settings and I am not well versed with such configurations. Could someone please help
?



Update:



Adding the contents of tasks.json, launch.json, c_cpp_properties.json, and terminal output for more clarity:



tasks.json:




"version": "2.0.0",
"tasks": [

"label": "build & debug file",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-o",
"$fileBasenameNoExtension",
"$file"
],
"group":
"kind": "build",
"isDefault": true

,

"label": "build & run file",
"type": "shell",
"command": "g++",
"args": [
"-o",
"$fileBasenameNoExtension",
"$file"
],
"group":
"kind": "build",
"isDefault": true
,
"problemMatcher":

]




launch.json:




// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "$workspaceFolder/test",
"args": ,
"stopAtEntry": false,
"cwd": "$workspaceFolder",
"environment": ,
"externalConsole": true,
"MIMode": "lldb"

]




c_cpp_properties.json:




"configurations": [

"name": "Mac",
"includePath": [
"$workspaceFolder/**",
"/usr/local/Cellar/gcc/7.1.0/include/c++/7.1.0",
"/usr/include/c++/4.2.1"
],
"defines": ,
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"

],
"version": 4


Current problem I am facing with this configuration is that I get the following error when I try: Terminal-> Run Build Task-> build & debug file:



 ld: warning: ignoring file /Users/xyz/Workspace/VSCode/.vscode/tasks.json, file was built for unsupported file format ( 0x7B 0x0A 0x20 0x20 0x20 0x20 0x22 0x76 0x65 0x72 0x73 0x69 0x6F 0x6E 0x22 0x3A ) which is not the architecture being linked (x86_64): /Users/xyz/Workspace/VSCode/.vscode/tasks.json
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The terminal process terminated with exit code: 1









share|improve this question























  • You should first be able to build from command line, using 'any editor'. If you have this, show your build process (edit the question). If not, start with that before tackling VS Code (or any "non-IDE" programmers editor) integration.
    – hyde
    Nov 9 at 20:24











  • @hyde I am able to build Cpp code from other editors such as Sublime Text and also debug them using CodeLite IDE. But it appears that we need to setup configs for the same in VSCode, specifically in the tasks.json, c_cpp_properties.json and launch.json. I don't know what to include in these files and am getting different errors while trying values from different sources for the aforementioned jsons. So, if you or anyone could provide the contents of the files, for an easy setup on Mac, it would be great.
    – user3760100
    Nov 10 at 9:20










  • Yeah, the thing is, there are dozens of ways to build C++ projects, with several layers of tools. Without knowing uour build process it is impossible to help. If you can get compile output view (as text, copy-paste) from some of these, it probably would help a lot here.
    – hyde
    Nov 10 at 9:49










  • @hyde, could you please tell me how to obtain info about my build process so that I can paste it here? I just remember installing xcode. I don't remember explicitly setting any build process for sublime, etc. Or rather, if the only 3 things I want from VS Code is 1) Intellisense code completion, 2) Ability to run a simple C++ file 3) Ability to debug a simple C++ file, what configurations should I mention in the config files above?
    – user3760100
    Nov 10 at 18:52










  • Your linker error hints at an options mismatch, are you compiler for x86, or other, and linking for x64? You look like you’ve got the build tools from homebrew, so it wouldn’t be obvious what the defaults that you have are.
    – Niall
    Nov 10 at 20:03












up vote
0
down vote

favorite









up vote
0
down vote

favorite











The closest similar answer I found for it is here



But that doesn't contain an answer to my question. I also went through the docs for trying to have C++ support to VSCode. I didn't find OSX specific settings and I am not well versed with such configurations. Could someone please help
?



Update:



Adding the contents of tasks.json, launch.json, c_cpp_properties.json, and terminal output for more clarity:



tasks.json:




"version": "2.0.0",
"tasks": [

"label": "build & debug file",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-o",
"$fileBasenameNoExtension",
"$file"
],
"group":
"kind": "build",
"isDefault": true

,

"label": "build & run file",
"type": "shell",
"command": "g++",
"args": [
"-o",
"$fileBasenameNoExtension",
"$file"
],
"group":
"kind": "build",
"isDefault": true
,
"problemMatcher":

]




launch.json:




// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "$workspaceFolder/test",
"args": ,
"stopAtEntry": false,
"cwd": "$workspaceFolder",
"environment": ,
"externalConsole": true,
"MIMode": "lldb"

]




c_cpp_properties.json:




"configurations": [

"name": "Mac",
"includePath": [
"$workspaceFolder/**",
"/usr/local/Cellar/gcc/7.1.0/include/c++/7.1.0",
"/usr/include/c++/4.2.1"
],
"defines": ,
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"

],
"version": 4


Current problem I am facing with this configuration is that I get the following error when I try: Terminal-> Run Build Task-> build & debug file:



 ld: warning: ignoring file /Users/xyz/Workspace/VSCode/.vscode/tasks.json, file was built for unsupported file format ( 0x7B 0x0A 0x20 0x20 0x20 0x20 0x22 0x76 0x65 0x72 0x73 0x69 0x6F 0x6E 0x22 0x3A ) which is not the architecture being linked (x86_64): /Users/xyz/Workspace/VSCode/.vscode/tasks.json
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The terminal process terminated with exit code: 1









share|improve this question















The closest similar answer I found for it is here



But that doesn't contain an answer to my question. I also went through the docs for trying to have C++ support to VSCode. I didn't find OSX specific settings and I am not well versed with such configurations. Could someone please help
?



Update:



Adding the contents of tasks.json, launch.json, c_cpp_properties.json, and terminal output for more clarity:



tasks.json:




"version": "2.0.0",
"tasks": [

"label": "build & debug file",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-o",
"$fileBasenameNoExtension",
"$file"
],
"group":
"kind": "build",
"isDefault": true

,

"label": "build & run file",
"type": "shell",
"command": "g++",
"args": [
"-o",
"$fileBasenameNoExtension",
"$file"
],
"group":
"kind": "build",
"isDefault": true
,
"problemMatcher":

]




launch.json:




// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "$workspaceFolder/test",
"args": ,
"stopAtEntry": false,
"cwd": "$workspaceFolder",
"environment": ,
"externalConsole": true,
"MIMode": "lldb"

]




c_cpp_properties.json:




"configurations": [

"name": "Mac",
"includePath": [
"$workspaceFolder/**",
"/usr/local/Cellar/gcc/7.1.0/include/c++/7.1.0",
"/usr/include/c++/4.2.1"
],
"defines": ,
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"

],
"version": 4


Current problem I am facing with this configuration is that I get the following error when I try: Terminal-> Run Build Task-> build & debug file:



 ld: warning: ignoring file /Users/xyz/Workspace/VSCode/.vscode/tasks.json, file was built for unsupported file format ( 0x7B 0x0A 0x20 0x20 0x20 0x20 0x22 0x76 0x65 0x72 0x73 0x69 0x6F 0x6E 0x22 0x3A ) which is not the architecture being linked (x86_64): /Users/xyz/Workspace/VSCode/.vscode/tasks.json
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The terminal process terminated with exit code: 1






c++ macos visual-studio-code vscode-settings






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 18:44

























asked Nov 9 at 18:21









user3760100

308214




308214











  • You should first be able to build from command line, using 'any editor'. If you have this, show your build process (edit the question). If not, start with that before tackling VS Code (or any "non-IDE" programmers editor) integration.
    – hyde
    Nov 9 at 20:24











  • @hyde I am able to build Cpp code from other editors such as Sublime Text and also debug them using CodeLite IDE. But it appears that we need to setup configs for the same in VSCode, specifically in the tasks.json, c_cpp_properties.json and launch.json. I don't know what to include in these files and am getting different errors while trying values from different sources for the aforementioned jsons. So, if you or anyone could provide the contents of the files, for an easy setup on Mac, it would be great.
    – user3760100
    Nov 10 at 9:20










  • Yeah, the thing is, there are dozens of ways to build C++ projects, with several layers of tools. Without knowing uour build process it is impossible to help. If you can get compile output view (as text, copy-paste) from some of these, it probably would help a lot here.
    – hyde
    Nov 10 at 9:49










  • @hyde, could you please tell me how to obtain info about my build process so that I can paste it here? I just remember installing xcode. I don't remember explicitly setting any build process for sublime, etc. Or rather, if the only 3 things I want from VS Code is 1) Intellisense code completion, 2) Ability to run a simple C++ file 3) Ability to debug a simple C++ file, what configurations should I mention in the config files above?
    – user3760100
    Nov 10 at 18:52










  • Your linker error hints at an options mismatch, are you compiler for x86, or other, and linking for x64? You look like you’ve got the build tools from homebrew, so it wouldn’t be obvious what the defaults that you have are.
    – Niall
    Nov 10 at 20:03
















  • You should first be able to build from command line, using 'any editor'. If you have this, show your build process (edit the question). If not, start with that before tackling VS Code (or any "non-IDE" programmers editor) integration.
    – hyde
    Nov 9 at 20:24











  • @hyde I am able to build Cpp code from other editors such as Sublime Text and also debug them using CodeLite IDE. But it appears that we need to setup configs for the same in VSCode, specifically in the tasks.json, c_cpp_properties.json and launch.json. I don't know what to include in these files and am getting different errors while trying values from different sources for the aforementioned jsons. So, if you or anyone could provide the contents of the files, for an easy setup on Mac, it would be great.
    – user3760100
    Nov 10 at 9:20










  • Yeah, the thing is, there are dozens of ways to build C++ projects, with several layers of tools. Without knowing uour build process it is impossible to help. If you can get compile output view (as text, copy-paste) from some of these, it probably would help a lot here.
    – hyde
    Nov 10 at 9:49










  • @hyde, could you please tell me how to obtain info about my build process so that I can paste it here? I just remember installing xcode. I don't remember explicitly setting any build process for sublime, etc. Or rather, if the only 3 things I want from VS Code is 1) Intellisense code completion, 2) Ability to run a simple C++ file 3) Ability to debug a simple C++ file, what configurations should I mention in the config files above?
    – user3760100
    Nov 10 at 18:52










  • Your linker error hints at an options mismatch, are you compiler for x86, or other, and linking for x64? You look like you’ve got the build tools from homebrew, so it wouldn’t be obvious what the defaults that you have are.
    – Niall
    Nov 10 at 20:03















You should first be able to build from command line, using 'any editor'. If you have this, show your build process (edit the question). If not, start with that before tackling VS Code (or any "non-IDE" programmers editor) integration.
– hyde
Nov 9 at 20:24





You should first be able to build from command line, using 'any editor'. If you have this, show your build process (edit the question). If not, start with that before tackling VS Code (or any "non-IDE" programmers editor) integration.
– hyde
Nov 9 at 20:24













@hyde I am able to build Cpp code from other editors such as Sublime Text and also debug them using CodeLite IDE. But it appears that we need to setup configs for the same in VSCode, specifically in the tasks.json, c_cpp_properties.json and launch.json. I don't know what to include in these files and am getting different errors while trying values from different sources for the aforementioned jsons. So, if you or anyone could provide the contents of the files, for an easy setup on Mac, it would be great.
– user3760100
Nov 10 at 9:20




@hyde I am able to build Cpp code from other editors such as Sublime Text and also debug them using CodeLite IDE. But it appears that we need to setup configs for the same in VSCode, specifically in the tasks.json, c_cpp_properties.json and launch.json. I don't know what to include in these files and am getting different errors while trying values from different sources for the aforementioned jsons. So, if you or anyone could provide the contents of the files, for an easy setup on Mac, it would be great.
– user3760100
Nov 10 at 9:20












Yeah, the thing is, there are dozens of ways to build C++ projects, with several layers of tools. Without knowing uour build process it is impossible to help. If you can get compile output view (as text, copy-paste) from some of these, it probably would help a lot here.
– hyde
Nov 10 at 9:49




Yeah, the thing is, there are dozens of ways to build C++ projects, with several layers of tools. Without knowing uour build process it is impossible to help. If you can get compile output view (as text, copy-paste) from some of these, it probably would help a lot here.
– hyde
Nov 10 at 9:49












@hyde, could you please tell me how to obtain info about my build process so that I can paste it here? I just remember installing xcode. I don't remember explicitly setting any build process for sublime, etc. Or rather, if the only 3 things I want from VS Code is 1) Intellisense code completion, 2) Ability to run a simple C++ file 3) Ability to debug a simple C++ file, what configurations should I mention in the config files above?
– user3760100
Nov 10 at 18:52




@hyde, could you please tell me how to obtain info about my build process so that I can paste it here? I just remember installing xcode. I don't remember explicitly setting any build process for sublime, etc. Or rather, if the only 3 things I want from VS Code is 1) Intellisense code completion, 2) Ability to run a simple C++ file 3) Ability to debug a simple C++ file, what configurations should I mention in the config files above?
– user3760100
Nov 10 at 18:52












Your linker error hints at an options mismatch, are you compiler for x86, or other, and linking for x64? You look like you’ve got the build tools from homebrew, so it wouldn’t be obvious what the defaults that you have are.
– Niall
Nov 10 at 20:03




Your linker error hints at an options mismatch, are you compiler for x86, or other, and linking for x64? You look like you’ve got the build tools from homebrew, so it wouldn’t be obvious what the defaults that you have are.
– Niall
Nov 10 at 20:03

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231352%2fhow-to-setup-vs-code-for-building-running-and-debugging-simple-c-files-in-osx%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231352%2fhow-to-setup-vs-code-for-building-running-and-debugging-simple-c-files-in-osx%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Darth Vader #20

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Ondo