Johnny Chan Johnny Chan - 1 year ago 73
Linux Question

Setting up environment for learning C

I am trying to learn C/C++ programming by following the MIT OCW materials. I am running a Windows PC and the course material mandates running all C/C++ programs under the Linux environment with the

compiler (for C and C++). They also require the use of
as a debugger.

I have already installed
from the MinGW package and am wondering if there is a specific instructions on how I can achieve the setup. For now I'd like to be able to set up the Linux,
, and
and at least write a simple program and compile and run it in the Linux environment. For now I've also installed VirtualBox but for some reason the virtual machine I created always gives the following message:
FATAL: No bootable medium found! System halted

I guess I am just lost in all the software packages/tools that are needed in order to start the learning. I've only used Microsoft Visual Studio before and so these whole new command prompts and tools are really confusing to me. Would be great if someone could give me the specific instructions on how I can start from a Windows PC and arrive at compiling and debugging a simple C program with
in the Linux environment.

Answer Source

I recommend you use VirtualBox to create a virtual machine. This is best because it sandboxes your development environment and you get a real Linux environment to work in. VirtualBox is free and open source and you probably won't need any advanced features you might see in VMWare or Parallels.

Now that you have the environment built you can create a directory where your project folders go. From the prompt just do mkdir projects, cd projects, mkdir helloworld, cd helloworld. Then, you can use the built-in editor nano to edit files. Type nano hello.c and then enter the following:

#include <stdio.h>
int main()
    printf("Hello, world\n");

Then type Ctrl-O to write out and then Ctrl-X to exit.

Then you just need to install gcc and I would suggest installing make as well:

$ sudo apt install gcc
$ sudo apt install make

Now to compile and test your first program in your development environment:

$ make hello
$ ./hello

Then you should see Hello, world on your screen.

I hope you find this helpful. Please comment if I was in any way unclear. There is much more you can do and that I suggest you do (like setup ssh, git) but they are a bit outside of the scope of this question.

EDIT: Valgrind and Un-mount Disk

From your helloworld project folder enter sudo apt install valgrind, then run valgrind ./hello.

Finally, go to Settings -> Storage and un-mount the installation ISO.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download