Download presentation
Presentation is loading. Please wait.
Published byDelilah Stephens Modified over 9 years ago
1
The Unix Environment and Compiling
2
Getting Set Up Your programs will be compiled and tested on the Departmental server ‘linprog’ The linprog servers (actually 4 computers) are maintained by the CS Systems Group and you must acquire an account for access (instructions here)here
3
Accessing linprog from a PC You should download 2 programs: SSH client – This program provides a secure connection to the server through which you can type terminal commands. SSH (Secure Shell) is a generic name for said service, a free windows SSH client can be found herehere X11 client - allows a server (such as linprog) to draw windows on your screen via an established SSH connection instead of solely using the terminal. A free trial of an X11 client Xwin32 can be found here and instructions on its use herehere
4
Accessing linprog from a Mac OS X has SSH and X11 clients built in. To access linprog with X11 active: Open ‘Terminal’ Application Type ‘ssh -X youracctname@linprog.cs.fsu.edu’ When setting up new account type ‘ssh newacct@shell.cs.fsu.edu’
5
Basic Unix Commands ls – list files and directories in current directory cd - change current directory to cd.. – change directory to next up in hierarchy cd ~ - change directory to your home directory mkdir - create sub-directory in current directory rm – remove file rm –R – remove directory and all its subdirectories cat - output text of to screen more - similar to cat, allows scrolling man - displays manual page for various unix and programming concepts
6
Emacs Emacs is a powerful Unix text editor that you can use to edit your programs on linprog Type ‘emacs ’ to open/create file for editing If X11 is running, you may type ‘&’ at the end of the command to retain terminal access while emacs is running (‘&’ is the background modifier for Unix commands)
7
Emacs Tips In the windows SSH client, you may want to edit the preferences to send delete when backspace is typed or backspace will not work as intended You can use ctrl-k to cut multiple lines an ctrl-y to paste them ctrl-x-s is used to save the file (Hold ctrl, type x and release, type s and release) ctrl-x-c quits emacs ctrl-g aborts a command if you find emacs has ‘frozen’ ctrl-s allows you to search the file for a keyword You can find other emacs commands herehere
8
Transferring Files To/From Server On a PC: The SSH client has a built in file transfer utility Connect to linprog, click the File Transfer Utility button on the SSH client, your machines files are on the left, linprog’s file system is on the right, you may drag and drop files back and forth On a Mac: To copy files to linprog type ‘scp linprog.cs.fsu.edu:~/’ To copy files from linprog type ‘sftp linprog.cs.fsu.edu’ and then ‘get ’
9
Using Multiple Files for a Project Although any program can be written in a single file, we often separate a program into several files: Header File – contain class declaration, ends in.h (circle.h) Implementation File – contains class definition (class member function implementations), ends in.cpp (circle.cpp) Driver File – contains main() and possibly other subroutines used in the program, ends in.cpp (driver.cpp) All of the programs in this class will have the above format
10
Reasons For Using Multiple Files Allows changes to the class implementation without affecting the class interface/structure Allows a class to be used in multiple driver programs Increases the opportunities for code reuse Code becomes more modularized It is infeasible to code a large project in a single file
11
Compilation Compilation is the process of transforming C++ source code into an executable file We will view compilation as two stages: Compile Stage Linking Stage
12
Compile Stage Performs preprocessor directives (#include, #define, etc.) Checks syntax of program (e.g. missing semicolon) Checks if functions/variables declared before use Doest NOT check if functions that are used are defined Creates machine code representation of file known as an object file (term not associated with ‘object-oriented’) An object file is not executable and may have functions that are used but have no definition (implementation) example?
13
Linking Stage Links the object code into an executable program. May involve one or more object code files. The linking stage is the time when function calls are matched up with their definitions, and the compiler checks to make sure it has one, and only one, definition for every function that is called. All member functions must also be defined There must be a main() function
14
Compiling a Multi-File Project See circle.h, circle.cpp, and driver.cpp g++ -c circle.cpp // performs compile stage on circle.cpp and creates object file circle.o g++ -c driver.cpp // performs compile stage on driver.cpp and creates object file driver.o g++ circle.o driver.o –o driver// links object files into executable file ‘driver’
15
#include In the previous example we did not compile circle.h, how was the Circle class declaration included in the compilation? Remember that preprocessor directives like #include are handled in the first part of the compile phase ‘#include 'filename' is literally replaced with the contents of the file ‘filename’ To avoid problems, only #include with header files We can run the preprocessor only by running the 'cpp' command
16
Review Describe what happens in the compile phase. What g++ compiler flag is used to only perform the compile phase on a file? What is the output? Describe what happens in the linking stage. What is needed for an executable to be created? Name some reasons for using multiple files for a project. sample1.cpp
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.