How can I compile/run C or C++ in Unix console or a Mac terminal?
(I know it, forget it, and relearn it again. Time to write it down.)
I found this link with directions:
http://www.wesg.ca/2007/11/how-to-write-and-compile-c-programs-on-mac-os-x/
Basically you do:
gcc hello.c
./a.out (or with the output file of the first command)
Use a makefile
. Even for very small (= one-file) projects, the effort is probably worth it because you can have several sets of compiler settings to test things. Debugging and deployment works much easier this way.
Read the make manual, it seems quite long at first glance but most sections you can just skim over. All in all it took me a few hours and made me much more productive.
just enter in the directory in which your c/cpp file is.
for compiling and running c code.
$gcc filename.c
$./a.out filename.c
for compiling and running c++ code.
$g++ filename.cpp
$./a.out filename.cpp
"$" is default mac terminal symbol
A compact way to go about doing that could be:
make foo && ./$_
Nice to have a one-liner so you can just re-run your executable again easily.