This week we are setting up your laptops and you will exercise to use Cevelop and the C++ compiler. We suggest you install Cevelop and a suitable compiler on your system natively for convenience and performance reasons. Check the setup instructions here: SetupEnvironment
We have implemented a plug-in for Cevelop that checks your code for various glitches, e.g. missing includes of standard headers. It focuses on various issues we usually also correct in your testat exercises. You should install this plug-in into your Cevelop.
In the IDE:
If you insist you can use a VM with Linux we provide.
We will be providing some memory sticks within the exercise labs to improve installation speed.
The C++ image consists of:
In this week you will reproduce all example programs in chapter 0 of Lucid C++ set up the corresponding Cevelop projects and compile and run the programs. You can find the chapter in SsW1. When you have accomplished these exercises you will:
- Be familiar with creating C++ projects in Cevelop
- Be able to split a simple application into:
- Library Project
- CUTE Test Project
- Executable Project
- Have implemented a testable hello world application in C++
- Have learned how to implement a unit test for a function using
- Have implemented your first simple class
If you struggle with the first steps in Cevelop, we have a tutorial video showing how to create, build and execute projects in Cevelop. This video also covers the first three of todays exercises. But we encourage you to first try it yourself to achieve a more sustainable learning experience!
Create a C++ project (Hello World Executable Project) in Cevelop, compile and run Hello World. This is a sanity check for your environment. Please report to your exercise supervisor immediately, if you can not make this work.
- In order to build the project you need to have some of its resources selected (the project in the Project Explorer or have a file of that project open in the focused editor) and then click the Hammer icon. This will build your project. The commands executed and the errors (if any) are reported in the Console view of Cevelop.
- To first run the (executable) project, you need to right-click the project in the Project Explorer and select Run As -> 1 Local C/C++ Application from the menu.
- You cannot run the project if you have never built it before (i.e. there must be an executable binary file in the project).
- Running the project will build it if necessary.
- Subsequent launches of the executable are accessible through the Run button in the toolbar.
- Create a single C++ project with Header, Implementation and Main Program
- Compiling the code:
- Build your project (Hammer icon in Cevelop).
- Do you get any errors?
- Read the output in the build console and understand the executed commands. You should be familiar with similar compiler calls from the Bsys module.
- Breaking the code:
- What happens, when you remove the #include preprocessor directives from either the main program or the sayhello source file?
- Experiment with the code by applying small modifications to prevent the compilation from succeeding. See what happens in Cevelop and when you try to build your project. Try to understand the error messages.
- Read chapter '0.6 A First Class' of the self-study (SsW1) material first.
- Create a C++ Static Library Project for your first class Hello.
- Add the class definition to a new header file Hello.h
- Add the member function implementation to an implementation file Hello.cpp
- Create a CUTE Library Test Project to actually test your class Hello.
see also SsW1 pdf
Please try the following variations of the code given and observe if you get compile errors, or if you get interesting results from running the program. Provide your answers on SolW1!
- Create a separate empty C++ project that depends on your library class Hello. Add a C++ source file to that new project and use your Hello class there. To be able to compile that file using the library, you need to set in the project's properties->C++ General->Paths and Symbols on the following tabs the corresponding entries (The CUTE Library Project wizard will do that for you):
- Includes: add to GNU C++ the project Hello as a workspace path
- Libraries: add "Hello" as the library (-> file will be libHello.a)
- Library Paths: add "/Hello/Debug" as a workspace path
- Referencs: tick the Hello project as referenced project (Active configuration)
- Remove the declaration of sayHello() from main(). The declaration is located in the header file, i.e. you have to remove the include of this header. What happens when you try to compile it?
- Remove the include guard from the header file sayhello.h and include the file twice in the corresponding main program hello.cpp. Do you expect an error? Do you get one? Why?
- Perform the same removal of the include guard and double inclusion with the file Hello.h containing the class Hello. Do you expect an error? Do you get one? Why?
- What happens when you compile hello.cpp without the implementation file containing the definition of sayHello()? Can you explain the error message?
- Since sayHello() is a function, you can call it from itself (sayhello.cpp). What happens if you call it after the output statement? What happens if you call it in front of the output statement? Why does this happen?
- On Linux or Mac you should limit the stack size using ulimit -s 32 before you run your change program or better run it in a debugger
- Project Setup
- Unresolved include to header file:
- Check spelling of header name.
- The referenced include path must be correct (In properties of referencing project -> C/C++ General -> Paths and Symbols -> Includes -> GCC C++ -- Add include to the path of the header file - specifically, if the header file is located in the src directory, that path has to be specified).
- Error in Cevelop
- Check type of error (See ReadingCompilerWarningsAndErrors). There different kinds of errors, but generally the compiler is always right!
- Type cannot be resolved / incomplete type:
- Check whether there is an include for this type. E.g. std::ostringstream with include to sstream.