Skip to content

Instantly share code, notes, and snippets.

@yeputons
Last active May 26, 2023 21:23
Show Gist options
  • Save yeputons/ba8c1f219e3a62c7526ad8955f697f33 to your computer and use it in GitHub Desktop.
Save yeputons/ba8c1f219e3a62c7526ad8955f697f33 to your computer and use it in GitHub Desktop.
CMake dynamic library example
#include "lib.hpp"
int main() {
talk();
}
cmake_minimum_required(VERSION 3.10)
project(dynamic-library-example CXX)
add_library(lib SHARED lib.cpp)
add_executable(app app.cpp)
target_link_libraries(app lib)
# cmake -B build-dir
# cmake --build build-dir
# cd build-dir
# ./app
#include "lib.hpp"
#include <iostream>
void talk() {
std::cout << "Hello World\n";
}
#ifndef LIB_HPP_
#define LIB_HPP_
void talk();
#endif // LIB_HPP_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment