Skip to content

Recitation 00 Setting up the Development Environment

jiju edited this page Sep 17, 2023 · 1 revision

Dependencies

Windows

  • Install CMake: CMake is a cross-platform free and open-source software tool for managing the build process of software using a compiler-independent method. Choose Cmake 3.21.2 64 bit version corresponding to your OS (Windows, mac or Linux).
  • Install Visual Studio Community 2019: It comes with the MSVC compiler (MSVC 14). During the install, select only "Microsoft Foundation Classes for C++". This will save you some space in your drive, and we really don't need the rest of the stuff that comes bundled with it.
  • Install Git: version control.

Required Libraries

Please note that you don't need to download and include the above libraries. I have already put the relevant files and libraries under the 'external' folder. As the lab machines are windows pcs, the lab/assignment starter codes will be tested only on Windows platform. We recommend Windows platform for the development. However, those who are comfortable with Mac/Linux may refer to the following information to set up the environment.

Mac

  • Install XCode (the g++ compiler and git are distributed therein)
  • Install Command Line Tools for Xcode (google how as it changes according to your OS version)
  • Install homebrew: package manager to install libraries
  • Install Git: version control. Finally we use homebrew to install all dependencies (execute these one by one in terminal):

brew install Cmake
brew install eigen
brew install pkgconfig

When we start working on OpenGL you will also need these (not necessary for ray tracing):


brew install homebrew/core/glfw3
brew install glew
brew install anttweakbar

Linux

Using the package manager (depends on distribution)

  • Install git
  • Install Cmake
  • Install the necessary libraries

Clone the Repository

If you haven't done so, please clone 'GraphicsLab' repo to your local machine. We can do this by going to the destination folder, opening 'Git Bash' and entering the following (alternatively, you can download the source code zip archive to the 'local folder' and extract it):

git clone https://github.com/jijup/GraphicsLab alt text

Helloworld in C++

Today's recitation is designed to make you familiar with the project repository structure, and procedure to build C++ project with Visual Studio on Windows using a simple program.

First, we will create a CMake to automatically generate a Makefile for Unix (Mac, Linux) or a Visual Studio solution for Windows. CMake is a cross-platform tool to for compiling your source code on different operating systems. CMake uses CMakeLists.txt, a script file that generates build files for a specific environment (OS, compiler etc.). A CMakeLists.txt is provided under the 'GraphicsLab' project.

TODO: Edit the CMakeLists.txt file to make it looks like the following:


# Declaring the used CMAKE version is mandatory
cmake_minimum_required(VERSION 3.10)
# This defines the name of our project 
project(GraphicsLab)
#--- Exercises, i.e., the name of first exercise
add_subdirectory(hello)

You can also find another CMakeLists.txt under the folder 'hello' which contains a set of directives and instructions describing the project's source files and targets (executable, library etc.). More details on CMake can be found here.

We have also provided a 'main.cpp' file under 'hello' contaning starter codes for today's reciation.

Thos who are not familiar with C++, please find below the main.cpp with a few comments explaining the overall structure of a .cpp file:


///========================== main.cpp ==========================
/// iostream provides basic input/output functionalities (cout)
#include 
/// iostream is part of the "std" namespace. The keyword "using" can 
/// be employed to avoid typing std::cout throughout the code
using namespace std;

/// main is the entry point of your program. It needs to be 
/// defined and always have this signature. The argc and argv 
/// are used to pass parameters from command line.
int main(int /*argc*/, char** /*argv*/){
    /// @todo find out how to print "Hello Cmake" to terminal
    cout << "Hello Cmake" << endl;
    /// The main function should always return a value.
    /// This tells the application whether it exited 
    /// correctly or not (legacy error management)
    return 0; ///< also EXIT_SUCCESS on UNIX
}

The main() function is the entry point of the program and needs to always be defined (with those exact parameters).

Building with Visual Studio

For building the solution using visual studio with CMake, please follow the instructions.

Open up the CMake GUI. This can be found by going to start menu and typing "cmake" (without quotes). Now do the following:

  • In the field labelled "Where is the source code:" enter the path where you extracted/cloned the source code. Suppose we cloned into C:\Users\UserName\Desktop\GraphicsLab. Then specify this address here (alternatively you can navigate with Windows explorer and copy the address from the search bar). alt text Figure 1: Specifying the source code in CMake GUI.
  • Create a folder namely "build" under C:\Users\UserName\Desktop\GraphicsLab. alt text Figure 2: The project build folder.
  • In the field labelled "Where to build the binaries:" enter the path to the build directory. Continuing with the previous example, then we can type C:\Users\UserName\Desktop\GraphicsLab\build. alt text Figure 3: Specifying the build folder in CMake GUI.
  • Hit configure. A pop-up will ask you if you want to create the directory. Say yes, and then another pop-up will appear asking for the generator. Here, pick Visual Studio 16 2019. Leave the default selection to "Use default native compilers" and hit finish. alt text Figure 4: Configure process.
  • If everything goes well, then you will see no red messages with ERROR next to them. If this is the case, then click generate. alt text Figure 5: Generate the solution file.
  • Go to the build directory and open the file called GraphicsLab.sln alt text Figure 6: .sln file under build folder.
  • You can now use Visual Studio to compile and test your code. alt text Figure 7: Start coding, compiling and testing your code.

TODO Edit the main.cpp file given under 'hello' to make it print "Hello CMake" to the console. Compile and run you C++ program and make sure that you can see the "Hello CMake" text printed in the console.

Trouble shooting for Linux/OSX

This is a compilation of solutions to frequent issues, brought up by students in the past years, when setting up the development environment (e.g. CMake). If your issue is not on the list, do email your instructor.

These solutions assume you have installed all the necessary requirements.

  • "No CMAKE_C_COMPILER can be found"

- Go to Projects, Build Settings and you should see a CMake settings list
- Click Add, then String
- Name the new setting CMAKE_C_COMPILER, the value is the path to gcc (or clang on OSX)
 ^(run "type -a gcc" or "type -a clang", to find the path value)

Issues?

Please post your problem on the "Issues" pane in the course repo. I will try to solve it ASAP!