I do this in my Dropbox so I can have quick access to all of my code across multiple computers. Organization is key when coding, so I recommend picking a special directory to store all of your code projects, then giving each project its own directory underneath. If the simplest C program imaginable leaves three files sitting around imagine the trash a more complex project will leave on your hard drive. At this point you’ve got three files sitting in the root of your C: drive that weren’t there before. Luckily, we can change this by telling GCC what the executable should be called with this command: gcc helloWorld.c -o helloWorld.exeĪnd your command window should look like this if everything went correctly: Now, it’s kinda odd for a Hello World program to be called ‘a.exe’. That ‘Hello World!’ means it worked - congratulations! To run the program, type the following command: This is the default name given to a program compiled with GCC. This command produces a new file in the root of the C: drive: a.exe To compile this file, type the following command: gcc helloWorld.c It means you didn’t save your text file in the right place.
The window should look something like this: Note: If you’re running on Windows Vista or above, you’ll have to run cmd.exe as administrator by right-clicking the cmd.exe entry:Īfterwards, agree to the UAC dialog that pops up.Ĭd C:\ ←-This will change the current directory to the root of the C: driveĭir *.c ←- This will show a listing of all of the files in the root of the C: drive with an extension of. Open the Start menu and enter ‘cmd’ into the run dialog and hit enter: Save the the above source code into a file called helloWorld.c in the root of the C: drive using your favorite text editor. (Note: these steps were written for Windows 7, but the same result can be achieved on nearly all versions of Windows with only minor changes to the steps). The steps to compile it are verbose at first, but they'll become second nature as you work more with code. Hello World is the simplest C program imaginable: #include īecause it’s so simple, it’s easy to verify that it’s working correctly: if you see ‘Hello World!’ printed when you run it, you can be sure you did everything correctly.
This article is available in PDF format for easy printingįor learning how to compile C files, it's best to start simple. Learning to use Unix-like development tools has direct applicability to developing code for embedded systems and will make you a fundamentally better programmer. You can use some variant of GCC to compile code for a wide variety of processors: AVRs, MSP430s, ARMs of all sizes, PowerPC - you name it and there's probably a GCC compiler for it. Additionally, the development tools discussed here have been adapted to a wide variety of embedded systems. If you've developed code before but never been able to break away from the chains of an IDE then this is the tutorial for you. I've found that the Unix approach to developing code produces efficient programmers with more autonomy and a broader understanding of all the various pieces that contribute to turning code into useful programs.
In addition, my goal with this whole series is to teach the basics of a Unix-like development environment. While there are many other tutorials out there covering roughly similar ground, I hope that you (a novice with some background in programming) find this tutorial to be more useful and approachable than other tutorials.
Specifically, how to use GCC to compile a C program and how to write a makefile to automate the process. In this article, I discuss how to use those tools we installed last time.
Step 0 discussed how to install GCC and the make utility with the expectation of writing and compiling your first C program. Coding Step 3 - High-Level Requirements.Coding Step 1 - Hello World and Makefiles.Coding Step 0 - Development Environments.