Download the latest version from the Releases page
git clone https://github.com/aangairbender/cg-singlefile-for-cpp.git
cd cg-singlefile-for-cpp
dotnet publish -c Release --use-current-runtime
- Any include of the following format (quotation marks
""
)will be replaced with content of#include "some_file.h"
some_file.h
- Any include of the following format (angle brackets
<>
)will be moved to the top of the output file#include <iostream>
- Same include will not be processed more than once (no duplication)
- Automatically skips lines containing
#pragma once
- Automatically skips lines starting with
//
(single-line comments). - If the line ends with "singlefile-skip-line" it will be skipped, e.g.
#include "some_local_tool.h" // singlefile-skip-line
Let's create a folder for a project
mkdir cg-contest
cd cg-contest
Let's create a my_math.h
file with a single sum
function:
int sum(int a, int b) {
return a + b;
}
Let's create a main.cpp
file and use my_math.h
there:
#include <iostream>
#include "my_math.h"
int main() {
std::cout << sum(1, 2) << std::endl;
}
Now let's try build it and run:
g++ main.cpp -o out
./out
3
Works fine. Now let's bundle this toy project into a single file:
cg-singlefile-for-cpp "main.cpp" -o "bundled.cpp"
Let's check what the tool generated for us by checking content of bundled.cpp
file:
#include <iostream>
int sum(int a, int b) {
return a + b;
}
int main() {
std::cout << sum(1, 2) << std::endl;
}
So it just replaced #include "my_math.h"
with the content of my_math.h
file.
Let's make sure it still works:
g++ bundled.cpp -o out2
./out2
3
Singlefile for cpp
Usage: cg-singlefile-for-cpp [arguments] [options]
Arguments:
main file The path to the entry point file (usually main.cpp)
Options:
-o | --output <value> output file path
-h | --help Show help information
-v | --version Show version information