A minimal example for creating, compiling and using a dynamic library in C++.
// test.h
#pragma once
int add(int a, int b);
int mult(int a, int b);
// test.cc
int add(int a, int b){ return a+b; }
int mult(int a, int b){ return a*b; }
$ g++ -shared -fPIC -o libtest.so test.cc
// main.cc
#include <iostream>
#include "test.h"
int main()
{
std::cout << "1 + 3 = " << add(1, 3) << std::endl;
std::cout << "1 * 3 = " << mult(1, 3) << std::endl;
}
$ g++ -o main libtest.so main.cc
$ ./main
1 + 3 = 4
1 * 3 = 3