Every program for which you submit a source file must run successfully on the SEASnet Linux server cs31.seas.ucla.edu using the g31 command we have set up, which is merely a special way of running g++ that catches more kinds of errors during execution.
What we're presenting here is a minimal set of instructions for helping a Windows or Mac user transfer a C++ program to that SEASnet Linux server to build and run. There are other ways to do this than what we show; the more you know about Linux, the more you can simplify or eliminate certain steps.
Let's assume you have a Visual C++ or an Xcode project consisting of the
source file from the Visual C++
writeup or the Xcode on a Mac writeup:
hello.cpp. (Note: It is inconvenient in Linux if the name of
a file contains space characters, so avoid giving your files such names.)
Here's what to do to run the program on the SEASnet cs31 Linux server:
First, note that you will be able to log into that SEASnet Linux server only from
Windows users: Install PuTTY on your own computer; a SEASnet writeup tells you how.
Copy your C++ source file to the SEASnet Linux server.
Mac users: Copy your C++ source file onto your Mac desktop and launch the
Terminal application. In Terminal, run the command scp
Desktop/hello.cpp yourSEASaccount@cs31.seas.ucla.edu:
(notice the colon at the end, no space before it), and enter your SEASnet
account password when prompted. This copies your file from your Mac to
the SEASnet cs31 Linux server.
If that command results in a scary warning about authenticity or DNS
spoofing, then run the command ssh
yourSEASaccount@cs31.seas.ucla.edu date and answer yes to the
question it asks. Then try the scp command again.
Alternatively, instead of using the name cs31.seas.ucla.edu, use one of the
names lnxsrv04.seas.ucla.edu or lnxsrv11.seas.ucla.edu or
lnxsrv14.seas.ucla.edu or lnxsrv16.seas.ucla.edu or lnxsrv17.seas.ucla.edu
consistently in this and subsequent steps.
Windows users: Install WinSCP on your computer. There is a Quick Start Guide. Use WinSCP to transfer the file to cs31.seas.ucla.edu, providing your SEASnet login name and password.
If you don't want to install WinSCP, then in a browser on your Windows
machine, navigate to https://file.io, click the Upload button and upload
your file, and note the link you're told in response (which will be of the
form https://file.io/XXXXXX). You will complete the
file transfer once you log into the Linux server in the next step.
Log in to the SEASnet cs31 Linux server. Here's how:
Mac users: From the Terminal application, run the command ssh
yourSEASaccount@cs31.seas.ucla.edu and enter your SEASnet
account password when prompted. This logs you into the cs31 Linux server.
If you get a message about the authenticity of cs31.seas.ucla.edu not being
able to be established, answer yes to the question asking you if you want to
continue.
Windows users: Launch PuTTY and type cs31.seas.ucla.edu for
the Host Name in the dialog box. If a dialog box titled "PuTTY Security
Alert" appears, click its Yes button. In the PuTTY console window (titled
something like "lnxsrv16.seas.ucla.edu - PuTTY"), log in to the Linux
server with your SEASnet login name. When prompted for your password,
type it in; the characters you type for your password will not produce
anything on the screen, not even bullets.
You will now be interacting on the remote Linux server with the command
interpreter program (the shell), whose default prompt is something
like bash-5.2$ or [yourname@lnxsrv16 ~]$.
For each command you type, the shell will execute it and then prompt you
for the next command. The shell is case-sensitive, so pay attention to
the distinction between lower and upper case.
Windows users who used https://file.io: To complete the file transfer, run the command
curl -s -L https://file.io/XXXXXX > hello.cpp
where XXXXXX are the characters at the end of the link you were told in response to your upload.
Our special way of running g++ is via a new command, g31, which you will have to set up. If you have never previously run the following command, run it now on the SEASnet Linux server; you will never have to run it again. If you do run it again, it will confirm that you are set up for running g31 on the SEASnet Linux server.
setupg31
Verify that the expected file is present by listing the contents of the current directory:
ls
Build an executable file from the source files. If we would like the
executable file to be named hello, we'd say
g31 -o hello hello.cpp
Like many Linux commands, if this command works, it doesn't say anything, so the shell would then just print its next prompt.
(You don't have to know this, but the setup process in step 5 modified the file~/.profile to create a bash function that causes the
above command to be executed as if it were /usr/local/cs/bin/g++
-std=c++17 -Wall -Wextra -Wno-sign-compare -Werror=return-type
-Wl,--rpath=/usr/local/cs/lib64 -fsanitize=address -fsanitize=undefined
-fsanitize=bounds -fno-omit-frame-pointer -o hello hello.cpp
instead. The /usr/local/cs/bin/g++ invokes g++ version
14.2.0; the SEASnet server's default is version 11.5.0. The
-std=c++17 enables C++17 language features. The
-Wall option asks the compiler to warn you about many
questionable constructs; the -Wextra -Wno-sign-compare asks
for warnings about even more questionable constructs. The
-Werror=return-type causes a certain warning to be treated as
an error. The other added options cause certain runtime errors to
terminate your program with an error message instead of silently
continuing and wreaking havoc.)
Compiler diagnostic messages are of the form
fileName:lineNumber:columnNumber:message
If the compiler detects any problems that you want to fix, then since we're assuming you're doing your primary development using Visual C++ or Xcode, you should make changes to your original Windows or Mac file. After checking in Visual C++ or Xcode that the modified program works as you expect it to, go back to step 1.
To execute the program hello that you built, you'd just say
hello
(If that doesn't work, try
./hello
instead.)
To exit the shell, say
exit
If you want to examine a file under Linux, a simple text editor you can use is Nano.
nano hello.cpp
You can navigate with the arrow keys. The bottom two lines of the display
show you some commands you can type. For example, control-C (indicated in
the bottom display as ^C) shows you what line number the cursor
is on. Control-O saves any changes you make to the file, and control-X exits
the editor.
We strongly recommend that you don't test your program using g31 just once, only after you're satisfied with it under Visual C++ or Xcode. Instead, do it periodically during your development, and certainly do it when you're trying to find an elusive bug. Sometimes people have spent hours trying to track down a problem during execution using Visual C++ when the g31 command would have immediately given them a warning that pointed to the mistake. Also, sometimes a program that appeared to work correctly under Visual C++ or Xcode relied on undefined behavior, but happened to get lucky for the student in a way that wasn't reproduced when we tested the program; testing using g31 might have shown different behavior, which would have suggested to the student that something was amiss.