Skip to main content

C++

Location: examples/cpp/

Same approach as C—preprocessor defines:

examples/cpp/main.cpp
#include <iostream>

// VERSION will be set by the compiler during build
#ifndef VERSION
#define VERSION "0.0.0"
#endif

int main() {
std::cout << "Sample C++ Application" << std::endl;
std::cout << "Version: " << VERSION << std::endl;
return 0;
}
examples/cpp/Makefile (excerpt)
build:
VERSION=$$(versionator version); \
g++ -DVERSION="\"$$VERSION\"" -o sample-app main.cpp

Run it

$ cd examples/cpp && just run
Getting version from versionator...
Building sample application with version: 0.0.16
Build completed: sample-app
./sample-app
Sample C++ Application
Version: 0.0.16

Source Code