Author: Hayden Smith
We can compile and execute this easily.
#include <iostream>
int main() {
// put "Hello world\n" to the character output
std::cout << "Hello, world!\n";
}
$ g++ -o hello hello.cpp
$ ./hello
We can compile and execute this easily.
#include <iostream>
#include "age.h"
int main() {
// put "Hello world\n" to the character output
std::cout << getAge() << "\n";
}
int getAge() {
return 5;
}
$ g++ -o age age.cpp
$ ./age
int getAge();
age.c
age.h
We can compile and execute this too.
Declarations in .h files, definitions in .c files
#include <iostream>
#include "age.h"
int main() {
std::cout << getAge() << "\n";
}
$ g++ -o age age_main.cpp age_lib.cpp
$ ./age
int getAge();
age_main.c
age.h
#include <iostream>
#include "age.h"
int getAge() {
return 5;
}
age_lib.c
The solution to this chaos is to use build systems.
With these systems, you simply have to declare files and relationships between them, and the build system will figure out what to run for you.
In COMP6771 we will be using CMake for compilation in conjunction with VScode for editing.
In COMP6771 we will be using CMake for compilation in conjunction with VScode for editing. We will be using C++20
Let's follow instructions in SETUP.md of tut01 to setup our environment. We can find tut01 on Gitlab via Webcms3.
The rest of this lecture will be a demo of the basic setup.
Catch2 is just one particular framework you can use to test with C++. More information on it can be found here.