CS 3358 (Data Structures and Algorithms) by Lee S. Koh

C++/C Programming in CS Linux Command-line Environment
A Minimal Survival Guide for CS 2308 and CS 3358 Classes by Lee S. Koh


Make Sure You Have a Texas State NetID (also referred to as Texas State Username)

If you don't have a Texas State email account, you most likely don't have a Texas State NetID.

Your Texas State ID number (e.g. A12345678) seen printed on your Texas State identification card is NOT your Texas State NetID (the format of which looks like zz99, zzz99, zz999, z_z99, zz9999).

If you don't have a Texas State NetID, refer to https://itac.txstate.edu/support/netid.html .
Make Sure You Have a CS Linux Account

Your CS department Linux account is linked to your Texas State NetID. To login with your Linux account you must use the same username and password you would use to login to a Texas State computer.

If you had such an account in a previous (not-too-distant-past) semester (perhaps because you were enrolled in CS 1428 or CS 2308 or CS 3358), chances are that the account remains active.

If you had not had such an account before (or in the not-too-distant-past) and ...


have a Texas State NetID


are enrolled in CS 1428 or CS 2308 or CS 3358


there should be an account automatically created for you within the first few days of the semester.

For more info on your Linux account, visit https://cs.txstate.edu/resources/linux.html.

If all things fail, send an email to cs_helpdesk@txstate.edu, including your Texas Net ID (e.g. zzz99) and a short message indicating that you are having difficulty logging into your CS Linux account.

Recommended Way of Doing C++/C Programming on CS Linux: Using SSH via PuTTY to access Linux shell environment and FileZilla to upload and download files (between local machine and server) 

Most if not all CS Lab (Windows-based) computers have PuTTY and FileZilla installed on them.

To do it on own machine:


Software authors’ download links:
PuTTY: https://www.putty.org/ Links for portable versions (that I found more convenient):
>   PuTTY Portable      
>   FileZilla Client Portable
FileZilla:  https://filezilla-project.org/
(For FileZilla, what’s needed is FileZilla Client, not FileZilla Server.)


For wireless connection, be sure to use one that is secured.



(An unsecured connection will not work.)


For Host (or Host Name) when connecting, type in one of following:



eros.cs.txstate.edu



zeus.cs.txstate.edu

You may find it useful to make a couple of suggested reconfigurations upon log-in via PuTTY (-->  you’d click the icon located on the upper left corner and select Change Settings... to bring up a dialog box for the following):


Select Appearance (under Window) and click the Change... button (under Font settings); then pick Courier New (for Font:), Bold (for Font style:), 16 (for Size:) and click the OK button. 


Select Colours (under Window), then make the 2 changes described below



(1)
click Default Foreground (under Select a colour to adjust:) and enter 0 (for Red), 0 (for Green), 0 (for Blue)



(2)
click Default Background (under Select a colour to adjust:) and enter 255 (for Red), 255 (for Green), 255 (for Blue)



and click the Apply button.

Some Useful Linux Commands 

logout sign off account

clear clear terminal screen (top-most line becomes command-line, the rest of screen cleared)

passwd change password

ls list contents (files and subdirectories) of current directory

mkdir subdir create subdir as new sub-directory (under the current directory)

rmdir subdir remove sub-directory subdir (from the current directory)

cd subdir make subdir (of current directory) the current directory

cd .. make the immediate parent directory (of current directory) the new current directory

cd make home directory (directory when first logged on) the new current directory

rm filename remove file named filename

more filename display contents of file named filename on screen, pausing at each screenful (and asking user to press a key) 

mv file1 file2 rename a file's name from file1 to file2

cp file1 file2 make a copy of file named file1 and name the new copy file2

{ctrl}+c (hit c while pressing the ctrl key) terminate (the currently running) program

How to Create, Compile, Link and Run a C++ Program on Your CS Linux Account 

Write source files (src1.cpp, src2.cpp, etc.).


Use a text editor (an example is vim on Linux but can be any other text editor that proves most expedient to you) to do it.


The disadvantage of using a text editor that is not on Linux itself is that you have to upload a file to Linux so you can perform test involving the file.



This can be cumbersome during debugging, as you have to download the file, make desired changes, and then upload the updated file each time you want to make changes and repeat a test involving the file.

Compile source files (src1.cpp, src2.cpp, etc.) to obtain corresponding object files (src1.o, src2.o, etc.)


NOTE: -Wall            turn on all warnings
-ansi -pedantic  reject non-standard (non-ANSI/ISO) features
-c               compile only (don't link)
(To enable C++11 support, add -std=c++11 to the list of options.)


g++ -Wall -ansi -pedantic -c src1.cpp



If successful, src1.o will be created.


g++ -Wall -ansi -pedantic -c src2.cpp



If successful, src2.o will be created.


And so on.

Link object files (src1.o, src2.o, etc.) to obtain executable file.


NOTE: -o  option to customize output file name (default file name is a.out)


g++ src1.o src2.o more_object_files_if_applicable -o executable_filename



If successful, executable file named executable_filename will be created.

Run executable file


./executable_filename

How to Create, Compile, Link and Run a C Program on Your CS Linux Account 

Follow the same steps given above (for a C++ program) but use gcc instead of g++.