Compiling(linux)
Compiling for Linux
Unit2: simple.c
- Create a new director called ex2
- Download and unzip zip file into this directory and check that the directory contains the source file simple.c
OR
Create simple.c and copy in code from simple code
- Edit to simple.c and make sure that:
(a) #include “stdafx.h” is commented out or does not exist
(b) Change the Microsoft entrpoint “int _tmain(int argc, _TCHAR* argv[])” to the normal ‘C’ entry point: int main(int argc, char* argv[])”.
(c) Add GLUT initialisation “glutInit(&argc, argv);” as the first line in main( ) if it is not there.
- Complie using: “gcc simple.c -o simple -lGLU -lglut -lGL -lm”
OR
Run the script “compile” that you downloaded in the zip file (but make it executable first by typing “chmod +x compile”).
- Check that your directory now contains the executable file “simple”
- Run “simple” by typing “simple”.
Other examples
- Download and unzip the zip file of all exercises for Microsof Windows
- Locate and copy the desired source code file into a new directory and call it something (e.g. filename.c).
- Open in your favorite code editor and comment out the line “#include “stdafx.h”
- Complie using: “gcc filename.c -o filename -lGLU -lglut -lGL -lm”
OR
for multiple files such as ex 8.1 use
“gcc filename1.cpp filename2.cpp -o filename -lGLU -lglut -lGL -lm”