Maartens Resource Compiler
  • CMake 56.3%
  • C++ 43.7%
Find a file
Maarten L. Hekkelman 8da7d40312
All checks were successful
test on FreeBSD / build (Release, c++, freebsd-latest) (push) Successful in 10s
test on Debian / build (Release, g++, debian-latest) (push) Successful in 2m41s
Finish move to forge
2026-05-12 15:50:12 +02:00
.forgejo/workflows Finish move to forge 2026-05-12 15:50:12 +02:00
.github Finish move to forge 2026-05-12 15:50:12 +02:00
cmake fix includes 2026-04-08 15:20:20 +02:00
doc New cmakefile, learned some new tricks lately 2022-12-03 11:24:04 +01:00
examples merged 2026-01-21 13:48:09 +01:00
rsrc Fixed serious bug due to insufficient testing... 2020-09-10 11:28:08 +02:00
src For windows 2026-04-08 15:38:08 +02:00
.clang-format fix includes 2026-04-08 15:20:20 +02:00
.clang-tidy fix includes 2026-04-08 15:20:20 +02:00
.gitattributes force correct eol char on rsrc test files 2023-11-16 08:44:04 +01:00
.gitignore More .ignore 2026-04-08 15:44:36 +02:00
.gitmodules New cmakefile, learned some new tricks lately 2022-12-03 11:24:04 +01:00
changelog fix includes 2026-04-08 15:20:20 +02:00
CMakeLists.txt fix includes 2026-04-08 15:20:20 +02:00
LICENSE Update LICENSE 2022-07-01 08:16:50 +02:00
README.md Finish move to forge 2026-05-12 15:50:12 +02:00

github CI github CI

Maartens Resource Compiler

Abstract

A long, long time ago there was an operating system that did things differently. One of the cool features of this OS was that applications were self contained. A single file was everything you needed to copy in order to install a new application. No need to use installers or install scripts that put dozens of files at the most obscure locations on your disk.

One of the technical features to make this possible was called resources: a kind of database in one of the two forks of a file, the other fork being the data fork.

Resources were mildly popular, other OS'es copied the concept in one way or another. The company that invented them abandoned the whole concept though, they thought they had something better....

Anyway, I still like being able to provide a single executable to the users of my software. And given the usefulness of resources I decided to create a compiler generating object files in the ELF executable format. Since using resource forks is not an option I decided to store the data in the static data section of an executable. The data can then be accessed through global variables.

New in version 1.3.4 is support for writing COFF files, so you can now use this type of resources in Windows as well.

Synopsis

First, create the mrsrc.h file that contains C++ classes to access the resources. This file can be generated by executing:

mrc --header -o mrsrc.h

Then include this file and use it:

 #include "mrsrc.h"
 
 int main()
 {
   mrsrc::rsrc hello("texts/greeting");
   if (hello)
   {
     std::string s(hello.data(), hello.size());
     std::cout << s << '\n';
   }
   
   return 0;
}

To create a resource file:

 echo "Hello, world!" > greeting
 mrc -o my-rsrc.o --root texts greeting
 c++ -o my-app foo.cpp my-rsrc.o

CMake integration

mrc comes with a mrc-config.cmake file installed at a suitable location. This means you can include mrc using a find_package call. The previous example might have a CMakeLists.txt file containing the following:

project(hello VERSION 1.0.0 LANGUAGES CXX)

# Include the mrc package file
find_package(mrc)

# The MRC_FOUND variable is set if MRC was found
if(NOT MRC_FOUND)
  message(FATAL_ERROR "mrc not found")
endif()

# The executable to create
add_executable(mrc-user ${CMAKE_CURRENT_SOURCE_DIR}/src/mrc-user.cpp)

# Write out the mrc header file and add the directory to the include paths
mrc_write_header(${CMAKE_CURRENT_BINARY_DIR}/mrsrc.hpp)
target_include_directories(mrc-user ${CMAKE_CURRENT_BINARY_DIR})

# Add the file hello.txt in the directory rsrc as resource 'hello.txt'
mrc_target_resources(mrc-user ${CMAKE_CURRENT_SOURCE_DIR}/rsrc/hello.txt)

Building mrc

To build mrc, you should use cmake:

git clone https://forge.hekkelman.net/maarten/mrc.git
cd mrc
cmake -S . -B build
cmake --build build
ctest --test-dir build
cmake --install build