SCMP 318 – Console Programs

Linux for programming

Goal

Convert a program from a previous course to work on your Linux VM. You choose c++ or python.

Turn in

All code and example of run on your Linux VM (Screenshot of terminal)

Links

Step 1 – Move your own program code to your linux server

You goal is to select a program from Data Structures or Intro to C++ and get it to run on the our Linux Server. The program must be at least 100 lines of code.

If your program has multiple source files, copy them all, including the .h files.

The easiest way to copy programs to your server is to use a file tranfer program like FileZilla. YOu should in stall this.

Once installed, start the pogram and enter the information about your server to connect. You can then transfer files and whole folders merely by dragging them in either direction.

Step 2 – build and run your programs

C++

Assume you have the following sources:

  • a.cpp
  • a.h
  • b.cpp
  • b.h
  • main.cpp Then you can comile and link the files into a executabl program using the commands:
user% g++ -c a.cpp 
user% g++ -c b.cpp 
user% g++ -c main.cpp 
user% g++ -o main a.o b.o main.o

How this works:
  • g++ is the GNU c++ compiler
  • -c compiles a c.pp file to an object file (.o). The source file (say a.cpp) is compiled and the compiled version is the sam name, but with a .o extension. An object file is a machine language version of the code, but no ready to be run because it hasn’t yet be “linked” to system conponents, and other .o file needed.
  • -o is the “Output” flag. It combines one or more object (.o) files into a complete ready to run program. The name after the -o is the name the program will have.
Python

You can run your program merely by typing:

python3 myprog.py

Where myprog.py is your program

Scroll to Top