This document shows how to create and download project files for use with the Cygwin tools from the command line. Most students will use the CLion IDE for writing and debugging their programs, but you can use Cygwin if you prefer using command line tools. This handout is also useful for ensuring you have correctly downloaded Cygwin and all the C++ tools used in Cygwin and in CLion.
In this section you will create and run a trivial C++ project/program (including editing it, and seeing how syntax errors are reported).
#include <iostream> using namespace std; int main() { cout << "Hello, World!" << endl; return 0; }
cmake_minimum_required(VERSION 3.3.2) set(CMAKE_CXX_COMPILER "/cygdrive/c/cygwin64/bin/clang++") set(CMAKE_C_COMPILER "/cygdrive/c/cygwin64/bin/clang") project(trivialtest) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(SOURCE_FILES main.cpp) add_executable(trivialtest ${SOURCE_FILES})
The following ~/ics46projects/trivialtest Cygwin64 Terminal window shows all these actions.
The lines at the top (before the pattis@PATTIS-HOME ~ prompt), are printed only the first time that you use Cygwin: they are informing you that default values for certain Unix files were created; you will not need to edit/modify these files.
The following Explorer window should appear on your screen.
You can use any combination of Windows and Cygwin commands to manipulate the files in this directory: whichever is simplest.
The following ~/ics46projects/trivialtest Cygwin64 Terminal window shows all these actions.
The failed results of attempting to rebuild the program appear after the make command. In this case, the Clang compiler accurately indicates the source of the error. I have lengthened the window so as not cause lines to wrap.
In this section you will download the course libraries and then download/build/run a project that contains various programs that use these libraries.
Generally, whenever you download projects, you will unzip them and then copy their directories into the directory that ics46projects shortcuts.
The following ~/ics46projects Cygwin64 Terminal window lists these four directories.
List the contents of the ics46project/test_all_data_types directory, by using the ls command. Notice that this project folder contiains various .cpp files and a CMakeLists.txt file
The following ~/ics46projects/test_all_data_types Cygwin64 Terminal window shows all these actions.
#include "driver_set.hpp" int main() { ics::DriverSet d; return 0; }
The following ~/ics46projects/test_all_data_types Cygwin64 Terminal window shows all these actions.
Experiment with this driver by entering commands (and their arguments, when prompted) to better understand the set data type. You can enter the q command to terminate the driver, or you can type ctrl-c to terminate the driver.
I suggest that you try terminating the driver with a q command; then, rerun the program and terminate it with ctrl-c.
The following explorer window should appear on your screen.
If the error pop-windowExperiment with this driver by entering commands (and their arguments, when prompted); it runs as it did in Cygwin. Note that when you enter the q command or ctrl-c, the program terminates and the MS-DOS window disappears.
appears, you must also add C:\cygwin64\bin to the user variable PATH: see steps 15-22 in the Cygwin handout.
So, when a program we run under Cygwin terminates, the screen retains the information printed (by cout) after the run terminates, but when we run it directly in an MS-DOS window, the window disappears after the run terminates. For example, if you find the trivialtest.exe file and run it by double-clicking this file, its MS-DOS windo will run and then immediately disappear.
Then, run the program (either in the Cygwin or a MS-DOS window) and issue the lf command (load from file); when prompted for the file name, just press the enter key to choose the default (loadset.txt).
The following ~/ics46projects/test_all_data_types Cygwin64 Terminal window shows all these actions.
Note that because the directory name input files contains a space, it appears in single quotes ('input files') and must appear in single quotes in all Cygwin commands.
IMPORTANT: If a program reads data files, the root directory for the specifying the files is the directory in which the .exe file appears. It is simplest to copy all the data files into this directory. An alternative would be to leave the files in the input files directory, and enter their names like input files/loadset.txt (note no quotes here: this is not a Cygwin command).
In the test_all_data_types project folder, the driver.cpp file has many main functions: we uncommented one (in step 4) to allow us to run the Set driver. If more than one main function is uncommented, attempting to build the code will result in the compiler specifying a redefinition of 'main' error.
The test_all_data_types project folder also contains many .cpp files (their names all start with test) that each contain one main function (each is a Googletest for one data type). If more than one file contains a main function, attempting to build the code will result in the linker specifying a multiple definition of 'main' error.
To switch this project from running the Set driver to the Set Googletest
Rebuild/Rerun the newly uncommented .cpp file.
The following ~/ics46projects/test_all_data_types Cygwin64 Terminal window shows all these actions.
We are now at the end of this handout. You will not need to repeat the first two sections during the course, but you will frequently download project folders and use them as demonstrated in section 2.