{"id":40669096,"url":"https://github.com/csiro-hydroinformatics/moirai","last_synced_at":"2026-01-30T07:15:11.372Z","repository":{"id":88767066,"uuid":"85764254","full_name":"csiro-hydroinformatics/moirai","owner":"csiro-hydroinformatics","description":"Manage C++ Objects's lifetime accessed through a C API","archived":false,"fork":false,"pushed_at":"2025-08-05T02:09:35.000Z","size":192,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-10T06:42:52.260Z","etag":null,"topics":["c-api","cpp","interoperability","reference-counting"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/csiro-hydroinformatics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-03-21T23:35:12.000Z","updated_at":"2025-06-16T01:00:08.000Z","dependencies_parsed_at":"2025-06-16T01:32:52.933Z","dependency_job_id":"0b03bf3d-1add-432c-a14a-2a924cc29d80","html_url":"https://github.com/csiro-hydroinformatics/moirai","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/csiro-hydroinformatics/moirai","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csiro-hydroinformatics%2Fmoirai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csiro-hydroinformatics%2Fmoirai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csiro-hydroinformatics%2Fmoirai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csiro-hydroinformatics%2Fmoirai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/csiro-hydroinformatics","download_url":"https://codeload.github.com/csiro-hydroinformatics/moirai/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csiro-hydroinformatics%2Fmoirai/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28630946,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T04:47:28.174Z","status":"ssl_error","status_checked_at":"2026-01-21T04:47:22.943Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-api","cpp","interoperability","reference-counting"],"created_at":"2026-01-21T09:17:59.402Z","updated_at":"2026-01-21T09:17:59.469Z","avatar_url":"https://github.com/csiro-hydroinformatics.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# MOIRAI: Manage C++ Objects's lifetime when exposed through a C API\n\n\u003ca href=\"https://scan.coverity.com/projects/csiro-hydroinformatics-moirai\"\u003e\n  \u003cimg alt=\"Coverity Scan Build Status\"\n       src=\"https://scan.coverity.com/projects/27474/badge.svg\"/\u003e\n\u003c/a\u003e\n\nWindows - master: [![Master build status](https://ci.appveyor.com/api/projects/status/8fobpshmwrmt3vmd/branch/master?svg=true)](https://ci.appveyor.com/project/jmp75/moirai/branch/master) testing: [![testing build status](https://ci.appveyor.com/api/projects/status/8fobpshmwrmt3vmd/branch/testing?svg=true)](https://ci.appveyor.com/project/jmp75/moirai/branch/testing)\n\nLinux - master: [![Linux master Build Status](https://travis-ci.org/csiro-hydroinformatics/moirai.svg?branch=master \"Linux master Build Status\")](https://travis-ci.org/csiro-hydroinformatics/moirai/builds) testing: [![Linux testing Build Status](https://travis-ci.org/csiro-hydroinformatics/moirai.svg?branch=testing \"Linux testing Build Status\")](https://travis-ci.org/csiro-hydroinformatics/moirai/builds)\n\n## Purpose\n\nThis C++ library is designed to help handling C++ objects from so-called opaque pointers, via a C API. Prominent features are:\n\n* counting references via the C API to C++ domain objects (instead of having to do so in each high-level language wrapper)\n* handle C++ class inheritance even via opaque pointers\n* mechanism for resilience to incorrect type casts when unwrapping opaque pointers (i.e. get an exception, not a nasty crash...)\n* thread-safe design\n\nANSI C code remains the most portable and least invasive way to access libraries in a binary compatible manner across compilers, mainly due to the incompatible name mangling schemes generated by C++ compilers.\n\n## Related resources and use cases\n\n`moirai` is agnostic to the technology binding to the C++/C API. The repository [c-interop](https://github.com/csiro-hydroinformatics/c-interop) features more advanced interoperability material with bingings in python, matlab and R. The python package [`refcount`](https://github.com/csiro-hydroinformatics/pyrefcount) also features in the python bindings.\n\n`moirai` features in the library [uchronia](https://github.com/csiro-hydroinformatics/uchronia-time-series/) for time series handling for ensemble simulations and forecasts in C++.\n\n## License\n\nMIT-derived CSIRO license (see [License.txt](./LICENSE.txt))\n\n## Naming\n\nIn Greek mythology, the [Moirai](https://en.wikipedia.org/wiki/Moirai) or Moerae (Ancient Greek: Μοῖραι, \"apportioners\"), often known in English as the Fates (Latin: Fatae), were the white-robed incarnations of destiny. [...]. They controlled the mother thread of life of every mortal from birth to death.\n\n## Requirements\n\nThis should be usable by any recent C++ compiler. This has been used by projects using gcc 4.8 and above, and Microsoft Visual C++ 2013 and above.\n\nUnit tests use the [\"Catch\" unit testing framework](https://github.com/philsquared/Catch).\n\n## Getting started\n\nYou may have a look at the unit tests under the 'tests' folder, in particular `moirai_test_api` and `moirai_test_lib` which are the closest to a typical use case. moirai_test is the next level you'll then want to look at.\n\nYou can follow [a walkthrough](./doc/Walkthrough.md) derived from the unit tests.\n\n## Compiling\n\n`moirai` is largely header-only for use in your projects, however there is a compiled shared library, and this is a deliberate design choice.\n\n### Windows\n\nYou can use the solution file under the `tests` folder. In order to compile the unit tests, you will need to use the template file `moirai.props.in`, copy it to your `Documents` folder (a.k.a. 'My Documents') e.g. to `C:\\Users\\username\\Documents\\moirai.props`. You likely need to adapt the line `\u003cMoirai_IncludePath\u003eC:/local/include\u003c/Moirai_IncludePath\u003e`. This should be the folder where `catch\\catch.hpp` is located (see Requirements). Leave other lines in `moirai.props` unchanged.\n\n### Linux\n\n```sh\nINSTALL_PREFIX=/usr/local # adapt\nGITHUB_REPOS=~/src/github_jm # adapt\n\nCLEAN_BUILD=\"rm -rf ../build/*\"\n\nCXX_COMP=-DCMAKE_CXX_COMPILER=g++\nC_COMP=-DCMAKE_C_COMPILER=gcc\nBUILD_CONFIG=\"-DCMAKE_BUILD_TYPE=Release\"\n# BUILD_CONFIG=\"-DCMAKE_BUILD_TYPE=Debug\"\n\nCM=\"cmake ${CXX_COMP} ${C_COMP} ${BUILD_CONFIG} -DBUILD_SHARED_LIBS=ON ..\"\nSUDO_CMD=\"sudo\"\ncd ${GITHUB_REPOS}/moirai\nmkdir -p build ; cd build\n$CLEAN_BUILD\n$CM\nmake\n./moirai_test\n./moirai_test_api\n\n$SUDO_CMD make install\n```\n\nIt is possible to uninstall using:\n\n```sh\n$SUDO_CMD make uninstall\n```\n\n## Background and rationale\n\nMoirai has been used to expose C++ libraries via a C API so that they could be accessed by users more fluent in tools such as R, Python and Matlab(r). Moirai helps to track the lifetime of C++ objects handled from these languages.\n\nMoirai is not a wrapper generator. There are tools to generate wrappers around C/C++ code for use from these and other languages. The venerable SWIG is but one, and you should assess whether this is what you want, along with or instead of Moirai. They are quite different beasts and likely to be complementary. Moirai targets a specific need: object lifetime via opaque pointers in C API. But why would you design an \"old style\" C API to access your C++ objects?\n\nAs an example, R on Windows (using the Rcpp package) requires a version of the GNU g++ compiler that may not be suitable to the library. A \"pure\" C API is needed needed to be able to compile the R wrappers with GCC and still use another compiler such as Visual C++ for the core library.\n\n### Related third party work\n\nI found out the [Loki](http://loki-lib.sourceforge.net/html/main.html) library. Nifty work, but a much larger and possibly different scope, more complicated. I have not thoroughly tasted (sic).\n\nMoirai is not an API bindings generator. [SWIG](http://swig.org) is. That said I assessed for most C API I have designed that I was [better off with my own](https://github.com/csiro-hydroinformatics/c-api-wrapper-generation), though.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsiro-hydroinformatics%2Fmoirai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcsiro-hydroinformatics%2Fmoirai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsiro-hydroinformatics%2Fmoirai/lists"}