Some quick gcc tips (by Eric Aschner in a Fall 2012 post to Piazza) I've seen this come up a few times, so I will give a (very) brief overview of using gcc. There are about a million options, but for this class we aren't going to be interested in the majority of them. Hopefully this helps a few people. If someone catches me missing something or screwing up a piece of it, please let me know in the comments! gcc is the Gnu Compiler Collection which is the general way to compile c programs on most unix based systems. Most of these options will also work on g++ (for c++ programs). If your program extension is ".cpp" or ".cc", use g++ even if the actual code is straight c. Otherwise (which is probably the only we we'll do it in this class) put your program extension as just ".c" and use gcc. General operation is "gcc program.c". This spits out any warnings or errors and then compiles the program if able, and dumps the executable as a.out. To run your program you would type "./a.out" into the console. If your program has multiple sources (several of your own include files, multiple .c files) you would use the same thing but type each file with a space in between. "gcc mainprogram.c myfunctions.c" Even with multiple files, you should only have one main function! a.out is a strange place to keep your executable, and if you have multiple programs in the same directory either you will have to continually rename them or you will keep overwriting them. Instead, we can use the output flag: "gcc program.c -o program" Immediately following "-o" is a space then the name you want your executable to be. You can put in spaces if you put your name in double quotes, but then you would always need to run it with double quotes. Generally, just don't use spaces for names. It will only cause problems later. The debug flag. If you want your executable to have debug information embedded in it, use "-g". "gcc -g program.c -o program" This works well with gdb, which I am sure will come up in conversation later. The default warnings only show a few things. If you are getting strange run time errors, you may want to look at all of your warnings. You should probably do this before turning it in. It's also good practice to look at them intermittently while coding anyway. gcc lets you change the warnings with the "-W" flag. (note the capital W) There are many options, the quickest way to get the bulk of them is just "-Wall". "-Wextra" turns on a few more options still, but these get to be rarely used options. Also note, the -W flag takes no spaces. Optimization (not really needed for this class, but you will come across it) can be done with "-O" commands. "-O" and "-O1" are the same thing. There is also "-O2", "-O3", and "-Ofast". Each one has a few more optimization levels that the last one didn't have. Generally, each one will produce larger but faster code and take longer to compile. "-Ofast" turns off some safety options, so I wouldn't recommend it. There is also "-Os" which optimizes for smaller code, not necessarily speed. Note the capital O (letter, not zero) and no space. Last is libraries. If you get an undefined reference error, you probably aren't including the library. Many of the most basic libraries will already be picked up, but a lot of them you have to tell gcc to use. Use "-l" (lower case l as in llama) then the short name. There is no space in between. The most common in this class will likely be "-lpthread" (for pthreads) "-lm" for math (if needed). If anything else comes up, ask here or google it. "gcc threadexample.c -o threadexample -lpthread" Also, you can move the order around for most of these flags, but any library flag should go after the sources or you may get an issue. So, to wrap it up: Compile example.c and myfuncs.c with threads and extended math support, name it larry, give me more warnings, and turn on debug mode: "gcc -g -Wall example.c myfuncs.c -o larry -lm -lpthread" For project 0 we were given a makefile, which should be much easier to use. For spin off programs like problem 3 on the last HW it should be easier to use gcc. Also if you add something into a project, it's possible the make file won't work for you. It'll usually be a library. Hopefully this is a good starting point.