I was wondering how to do it, so I intended to proceed on two different machines running Linux (Ubuntu 19.10 developer version), to see how to do so. Any additional help most welcome!
Walkthrough (Ubuntu, working on 19.10 developer version)
How to configure VSCode to compile and run CS50's C code?
1/ Choose a folder like home/user/MOOCs/Harvard/C/
Where you will save all of your c files
2/ Download CS50 library into that directory
Open terminal and go to the path home/user/MOOCs/Harvard/C/ for instance Source: https://cs50.readthedocs.io/library/c/
Then execute the following:
curl -s https://packagecloud.io/install/repositories/cs50/repo/script.deb.sh | sudo bash sudo apt install libcs50
if necessary install curl if it's not present on your system:
sudo apt install curl
(if you experience other issues, see the further below note, in bold)
3/ In VS Code
Open your first c file: VS Code prompts: The 'C/C++' extension is recommended for this file type.
Proceed and click "Install"
Then VS Code might prompt for the insiders extension which is not necessary at this point:
"Remind me later" can be a choice.
After that it's time to configure VS Code to be able to use CLANG Thus then press shift + crtl + P then type c and choose edit configurations (UI) in the drop-down list Then, in the Compiler path: Specify a compiler path or select a detected compiler path from the drop-down list. Type:
if the field in the UI turns red, and says "Cannot find: /usr/bin/clang" it's ok, just install clang:
sudo apt install clang
Then VS Code should accept the compiler path automatically (no need to restart it)
4/ In Compiler arguments, on a separate line (be sure)
Then intellisense mode choose:
(supposing you use a 64 bits architecture)
Then in C standard:
Which is the standard used by CS50.
5/ Then test your new configuration:
from the view menu > terminal then invoque:
clang -o resize-more resize-more.c -lcs50
Note: in case like me on this machine you experience an issue
1/ you can change <> by "" in the headers:
2/ if you experience issues with -lcs50 clang option
2.1/ Head to troubleshooting here: https://github.com/cs50/libcs50/issues/113
2.2/ If that doesn't work, compile manually, instructions here: https://github.com/cs50/libcs50#from-source-linux-and-mac
As of me, after completing these steps, it works! (in VS Code terminal)
The last step is to make it work through compiling in VS Code (you can always use the terminal window underneath and pass the commands in doubt)
Terminal > Run build task > C/C++ clang build active file
Note: it might be that the config struggles with the arguments. In my case on my backup machine, the argument -o was already passed after the first filename, then I just added -lcs50 which appears afterwards and it still compiles and work without errors, but you can always double check by comparing the results of calling clang in the attached below terminal window of VSCode
Happy offline coding!