Compiling(linux)

Compiling for Linux

Unit2: simple.c

  1. Create a new director called ex2
  2. 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
  3. 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.
  4. 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”).
  5. Check that your directory now contains the executable file “simple”
  6. Run “simple” by typing “simple”.

Other examples

  1. Download and unzip the zip file of all exercises for Microsof Windows
  2. Locate and copy the desired  source code file into a new directory and call it something (e.g. filename.c).
  3. Open in your favorite code editor and comment out the line “#include “stdafx.h”
  4. 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”

Comments are closed.