I am trying to run code in VScode (a simple HelloWorld) and it only gives back " error: linker command failed with exit code 1 (use -v to see invocation)". I basically cant execute anything, even though i have also modified the json file to execute c/c++. This is the code I have ran:
Note (I am using a Mac)
#include <stdio.h>
int main()
{
printf("Hello");
return 0;
}
And it returns (in terminal):
ld: open() failed, errno=2 for 'build/tut5_calc2'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Things I have tried, and their results:
1.- I tried giving permission to vscode to access my files, I also gave permission to finder to access documents, and putting in the terminal: cd Users/"myusername"/Documents/"Foldername"/"docname"
1.-Result: Previous to the change, it was giving me "permission denied" now that was fixed, but when running the code, it gave me the same error ("error: linker command failed with exit code 1 (use -v to see invocation)")
2.- I tried to, once doing step 1, debbuging and running.
2.- Result: Only "runs" if i debbug and run (if i only "run c file" ) it gives the same clang error 1. However, it only works once and shows the "output" in the debugger but i cant interactuate with it (I cant input), and i have to close VScode, reopen it, and rerun and debugg ...
3.- After searching i found a comment elsewhere saying the problem might have been the "#include", so i eliminated it from the code.
3.-Result:
error: call to undeclared library function 'printf' with type 'int (const char *, ...)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
printf("Hello");
Basically, I cant run my code... If anybody knows how to fix this, or how to really run code in VScode, I would greatly appreciate it. Thanks in advance.
Edit1: I have found my error, it is simple but I believe it will be useful for others who review this post: Solution:When creating a new c file from scratch in VScode, create a folder called "build". This solves it.