AGENDA¶
- Introduction to C++17
- First program: Hello World
- Compile with g++
- Intro to Makefile
- Intro to CMake
- Project structure
- Mini exercises
Why C++?¶
- Widely used in embedded, power electronics, and system testing
- High performance and control
- Large ecosystem (STL, libraries)
- Industry standard for engineering projects
Hello World in C++¶
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}
Compile and Run¶
g++ main.cpp -o main
./main
Makefile (Intro)¶
- Automate compilation
Example
Makefile:
all:
g++ main.cpp -o main
clean:
rm -f main
- Run:
make
make clean
CMake Basics¶
- Cross-platform build system generator
- Easier for larger projects
Minimal CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(HelloWorld)
add_executable(main main.cpp)
Building with CMake¶
mkdir build
cd build
cmake ..
make
./main
Project Structure¶
myproject/
├── src/
│ └── main.cpp
├── inc/
├── CMakeLists.txt
└── build/
Mini-Exercises¶
Exercise 1¶
- Create a new folder
cpp_project - Write
main.cppwith Hello World - Compile with
g++and run
Exercise 2¶
- Write a Makefile to compile
main.cpp - Use
maketo build andmake cleanto remove binaries
Exercise 3¶
- Create
CMakeLists.txtas shown - Build with CMake in
build/ - Run the program
Survival Package (C++ Project Setup)¶
g++ main.cpp -o main- Makefile:
make,make clean - CMake:
cmake .. && make - Project structure:
src/,inc/,build/
Wrap-Up¶
- Wrote and compiled first C++ program
- Learned Makefile basics
- Used CMake to build project
- Understood standard project structure
Resources¶
Next Session¶
- Testing your software with Google Test