/
Unix Programming Environment Unix Programming Environment

Unix Programming Environment - PowerPoint Presentation

test
test . @test
Follow
352 views
Uploaded On 2018-12-11

Unix Programming Environment - PPT Presentation

Editors Compiler Debuggers Make Unix IO redirection Project submission Tar files Other useful Unix commands 1 Editors We recommend two editors vi and emacs You should really retire ID: 739867

files file directory tar file files tar directory input cpp program emacs core unix header submission target resource makefile

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Unix Programming Environment" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Unix Programming Environment

EditorsCompilerDebuggersMake Unix I/O redirectionProject submissionTar filesOther useful Unix commands

1Slide2

Editors

We recommend two editors: vi and emacsYou should really retire “pico” for editing programs

vi, c

lassical editor on Unix/Linux

When we say “vi”, we mean “vim” (vi improved for programmers)Normally vi has been linked to vimRun the following command to check if your vi has been linked to vim (alias) which viColor syntax highlighting (for vim)Edit your .vimrc file under your home directory and add the following line syntax onTwo modes: insert and command. Default mode is commandEntering insert mode: a, i, o or O

2Slide3

Emacs

Emacs configuration file.emacs under your home directoryYou can shorten the commands by defining commands in your .emacs resource file (for example, meta-g to go a line, ctrl-c

ctrl-c

to comment, etc)

See r1/emacs_example for an example configuration fileYou can copy it to .emacs under your home directory if you want to use this resource file for emacsThis configuration supports color syntax highlight3Slide4

Other Popular Editors

SublimeNotepad++PspadClionAtomVSCodeSome of them work on Windows

4Slide5

Compiler

g++Examples g++ example.cppg++ -c example.cppg++ -g example.cppg++ -Wall example.cppg++ -Wall example.cpp –lm

C++11

g++ -

std=c++0x example.cpp g++ -std=c++11 example.cpp // since g++ 4.7Note that you will need to specify c++11 standard when you compile some of the assignments5Slide6

Some Important Options of g++

-WallThis enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros. -pendanticIssue all the warnings demanded by strict ISO C and ISO C++; reject all programs that use forbidden extensions, and some other programs that do not follow ISO C and ISO C++.

See g++ manual for details

We recommend you to enable these two options when you compile your program

6Slide7

Header Files

If you have a header file (e.g., example.h) in the same directory as the main program (e.g., example.cpp), there are two ways for you to include the header file in the main program, using either “example.h”, or <example.h>Double quote

Searching current directory for header file

Angle bracket

Searching system directory for header fileWhich can be changed by the –I operation of compiler g++g++ -I. –o examplex example.cpp (example.cpp contains #include <example.h>7Slide8

Debugger

The code must be compiled with –g option.ddd, xxgdb, gdb

The power of a debugger:

Finding the line that causes

coredump.See example:Break point/show value/change value/step/next/continue/printDemo with r1/example2.cppTo compile: make example2.x8Slide9

Debug Segmentation Fault with Core dump File

A file containing memory image of process when it terminates (crashes)A common reason of core dump file not created is resource limit on core fileControlling core file size is shell specific

csh

:

limit [resource] [limit], or simply unlimit to remove all limitsWhere resource should be coredumpsizesh: ulimit -c [limit]Load core dump file into debugger

gdb

:

gdb

executable_file

coredump_file

ddd: ddd

executable_file

coredump_file

To locate the line that causes core dump

backtrace

(or

bt

)

Demo with r1/example2.cpp

9Slide10

Debug Segmentation Fault w/o Using Core dump File

Load executable into debuggdb: gdb executable_file

ddd

: ddd executable_fileRun program in debugrun (gdb command)After you run the program, you will encounter segmentation fault, gdb will show some info regarding the error and line causing problemYou can also use a few gdb commands to locate problemwherebacktrace

(or

bt

)

Demo with r1/example2.cpp

Read

gdb

users manual to get more information and commands

10Slide11

Make

A tool to update files that are derived from other files. Great for software development.Discussions based on GNU make utility

make command

make [-f

makefile][option][target]Common make file names are Makefile, makefile, in that orderThe default files can be overwrite with the –f optionmake –f myprog.mk

11Slide12

Make

Explicit rules:Target [target…] : [prerequisite…]<tab> command<tab> command…

Example:

proj1.x: proj1.h proj1.cpp

g++ -std=c++11 proj1.cpp –o proj1.x12Slide13

Make

Implicit rules:Tell make how to use certain customary techniques to remake a target so that you do not have to supply the rulesFor example, look at the following makefile

make will search an implicit rule to make proj1.o since we did not specify how to create

13

proj1.x : proj1.h proj1.o

g++ -

std

=

c++

11 -o proj1.x proj1.o Slide14

Make

Variable definitions:String1 = string2E.g. CC=

gcc

CFLAG=-Wall –

ansi –pedanticSome automatic variables$@: target file$<: name of first prerequisite$?: name of all prerequisites newer than target$^: name of all prerequisitesSee makefile1 and makefile2See makefileWhich can be used to compile any simple programs, e.g.make example1.xmake example2.x

14Slide15

I/O Redirection

For a program (or command) that reads from the standard input (normally, the keyboard), we can redirect input so that the input is taken from a file, instead of standard input, for examplecmd1 < file1Which redirects file1 to be the input to cmd1We will frequently use input redirection to test a number of projects.

For these, your program will read from standard input, and you do not need to worry about anything in your program regarding the input redirection. It is handled by Unix shells.

Similarly, we also have output redirection

cmd2 > file2And they can be combinedcmd3 < file1 > file2You can find more information athttp://www.tldp.org/LDP/intro-linux/html/chap_05.html15Slide16

Project Submission

All projects will be submitted via Canvas assignment pageYou can submit multiple times (otherwise, let us know)16Slide17

Tar files

You need to compress all files (including makefile, header files, source code files, etc) into a single file when you submit your projectsSome common tar usages (assuming all files you need to submit are under proj1 directory)

To tar all files

tar –

cvf proj1.tar *You need to be extremely careful, or you risk to overwrite an existing file (for example, some students in the past forgot to specify proj1.tar)To check the contents in the tar filetar –tvf proj1.tarTo untar a tar file to get all files in the tar file (in order to not overwrite existing files, you should do this in a different directory)tar –xvf proj1.tarTo reduce tar file size, please do not include object or executable files in your tar file

17Slide18

Submission Verification

The most reliable way to verify if you have submitted the correct version is to Download the submission to a new directoryUntar the tar file,Check the source filesCompile and run it to make sure it is correct

Contact the FSU/ITS team if you cannot download your submission.

Do not save and

untar the submission file in the same directory of your working codeWhen you untar, it will overwrite your existing programs18Slide19

Other Useful Unix Commands

Manual page of any commandman commandLog into a remote machinessh username@remote_machineFor example: ssh

duan@linprog.cs.fsu.edu

Retrieve a file or directory from a web server

wget URLCreate an empty file or change timestamptouch filenameChange permission of a programchmod mode filenamechmod u+x proj2.x (to add executable permission)If you download an executable program but it does not run, you should check the permission first.19