* . *
  • About
  • Advertise
  • Privacy & Policy
  • Contact
Sunday, December 21, 2025
Earth-News
  • Home
  • Business
  • Entertainment
    WildBrain Sells Stake in Peanuts Holdings to Sony Pictures Entertainment – Licensing International

    WildBrain Sells Stake in Peanuts Holdings to Sony Pictures Entertainment – Licensing International

    Country music star, wife are getting divorced: ‘We are no longer suited to be married’ – PennLive.com

    Country Music Star and Spouse Reveal They Are No Longer Suited for Marriage

    Nate Bargatze is leaving his podcast — and Utah recently saw why – Deseret News

    Nate Bargatze Is Leaving His Podcast – What Utah Fans Recently Went Through

    State Farm Arena Ranks In The Top 5 Live Entertainment Venues In The U.S. & Top 7 In The World, According To Billboard – Secret Atlanta

    State Farm Arena Ranks In The Top 5 Live Entertainment Venues In The U.S. & Top 7 In The World, According To Billboard – Secret Atlanta

    Walk on White features Conchettes and Santa – keysnews.com

    Uncover the Enchantment of Conchettes and Santa in Walk on White

    Blizzard Entertainment President on BlizzCon 2026, 35th Anniversary Plans – Variety

    Blizzard Entertainment President Reveals Thrilling BlizzCon 2026 and 35th Anniversary Celebrations

  • General
  • Health
  • News

    Cracking the Code: Why China’s Economic Challenges Aren’t Shaking Markets, Unlike America’s” – Bloomberg

    Trump’s Narrow Window to Spread the Truth About Harris

    Trump’s Narrow Window to Spread the Truth About Harris

    Israel-Gaza war live updates: Hamas leader Ismail Haniyeh assassinated in Iran, group says

    Israel-Gaza war live updates: Hamas leader Ismail Haniyeh assassinated in Iran, group says

    PAP Boss to Niger Delta Youths, Stay Away from the Protest

    PAP Boss to Niger Delta Youths, Stay Away from the Protest

    Court Restricts Protests In Lagos To Freedom, Peace Park

    Court Restricts Protests In Lagos To Freedom, Peace Park

    Fans React to Jazz Jennings’ Inspiring Weight Loss Journey

    Fans React to Jazz Jennings’ Inspiring Weight Loss Journey

    Trending Tags

    • Trump Inauguration
    • United Stated
    • White House
    • Market Stories
    • Election Results
  • Science
  • Sports
  • Technology
    Technology is powerful but unforgiving when misused – Supreme Court judge warns – GhanaWeb

    Supreme Court Judge Issues Stark Warning: Technology’s Power Can Be Dangerous When Misused

    The 8 worst technology flops of 2025 – MIT Technology Review

    The 8 worst technology flops of 2025 – MIT Technology Review

    Bangor School District receives new CNC router technology from First National Bank – news8000.com

    Bangor School District Unveils Cutting-Edge CNC Router Technology Thanks to Local Support

    6G discussions: How things have changed – 5gtechnologyworld.com

    The Evolution of 6G: How the Conversation Has Transformed

    Retail supply chains brace for a redefined 2026 as tariffs, technology gaps, and nearshoring upend old models – Raleigh News & Observer

    Retail Supply Chains Revolutionize in 2026: How Tariffs, Technology Gaps, and Nearshoring Are Shaping the Future

    China exploits US-funded research on nuclear technology, a congressional report says – ABC News

    Congressional Report Uncovers China’s Exploitation of US-Funded Nuclear Technology Research

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
No Result
View All Result
  • Home
  • Business
  • Entertainment
    WildBrain Sells Stake in Peanuts Holdings to Sony Pictures Entertainment – Licensing International

    WildBrain Sells Stake in Peanuts Holdings to Sony Pictures Entertainment – Licensing International

    Country music star, wife are getting divorced: ‘We are no longer suited to be married’ – PennLive.com

    Country Music Star and Spouse Reveal They Are No Longer Suited for Marriage

    Nate Bargatze is leaving his podcast — and Utah recently saw why – Deseret News

    Nate Bargatze Is Leaving His Podcast – What Utah Fans Recently Went Through

    State Farm Arena Ranks In The Top 5 Live Entertainment Venues In The U.S. & Top 7 In The World, According To Billboard – Secret Atlanta

    State Farm Arena Ranks In The Top 5 Live Entertainment Venues In The U.S. & Top 7 In The World, According To Billboard – Secret Atlanta

    Walk on White features Conchettes and Santa – keysnews.com

    Uncover the Enchantment of Conchettes and Santa in Walk on White

    Blizzard Entertainment President on BlizzCon 2026, 35th Anniversary Plans – Variety

    Blizzard Entertainment President Reveals Thrilling BlizzCon 2026 and 35th Anniversary Celebrations

  • General
  • Health
  • News

    Cracking the Code: Why China’s Economic Challenges Aren’t Shaking Markets, Unlike America’s” – Bloomberg

    Trump’s Narrow Window to Spread the Truth About Harris

    Trump’s Narrow Window to Spread the Truth About Harris

    Israel-Gaza war live updates: Hamas leader Ismail Haniyeh assassinated in Iran, group says

    Israel-Gaza war live updates: Hamas leader Ismail Haniyeh assassinated in Iran, group says

    PAP Boss to Niger Delta Youths, Stay Away from the Protest

    PAP Boss to Niger Delta Youths, Stay Away from the Protest

    Court Restricts Protests In Lagos To Freedom, Peace Park

    Court Restricts Protests In Lagos To Freedom, Peace Park

    Fans React to Jazz Jennings’ Inspiring Weight Loss Journey

    Fans React to Jazz Jennings’ Inspiring Weight Loss Journey

    Trending Tags

    • Trump Inauguration
    • United Stated
    • White House
    • Market Stories
    • Election Results
  • Science
  • Sports
  • Technology
    Technology is powerful but unforgiving when misused – Supreme Court judge warns – GhanaWeb

    Supreme Court Judge Issues Stark Warning: Technology’s Power Can Be Dangerous When Misused

    The 8 worst technology flops of 2025 – MIT Technology Review

    The 8 worst technology flops of 2025 – MIT Technology Review

    Bangor School District receives new CNC router technology from First National Bank – news8000.com

    Bangor School District Unveils Cutting-Edge CNC Router Technology Thanks to Local Support

    6G discussions: How things have changed – 5gtechnologyworld.com

    The Evolution of 6G: How the Conversation Has Transformed

    Retail supply chains brace for a redefined 2026 as tariffs, technology gaps, and nearshoring upend old models – Raleigh News & Observer

    Retail Supply Chains Revolutionize in 2026: How Tariffs, Technology Gaps, and Nearshoring Are Shaping the Future

    China exploits US-funded research on nuclear technology, a congressional report says – ABC News

    Congressional Report Uncovers China’s Exploitation of US-Funded Nuclear Technology Research

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
No Result
View All Result
Earth-News
No Result
View All Result
Home Technology

C++ Modules: Packaging Story

October 18, 2023
in Technology
Share on FacebookShare on Twitter

Introduction

For the longest time, textual inclusion of header files has been the way to share declarations across multiple translation units. Thus, the concept of a packaged library has always involved “include files”, as well as the binary library files themselves, and this is how libraries are packaged for development. In order to make calls to functions provided by a library, we must first include the header that declares the funcion, for example:

#include

int main() {
fmt::print(“Hello, world!n”);
}

C++ 20 introduces Modules as a new way to share declarations (and definitions!) across multiple translation units. With modules, we would have something like this on the calling side:

import fmt; // Unlike the #include preprocessor directive, which simply performs textual inclusion of the referenced file, the import keyword is a C++ language feature which behaves differently. Modules have advantages over legacy headers, by providing better isolation:

Importers can only see entities that are explicitly exported
Importers cannot affect the code being imported
The imported code cannot affect the state of the preprocessor in the importing code
Import order does not matter, and importing “twice” does not require special care

With modules, we could avoid issues such as headers defining commonly named identifiers as macro functions, rogue “using namespace” directives in header files and we could finally put the recurrent #pragma once vs include guards debate to rest.

Binary Module Interfaces

Let’s assume we have a library that already supports C++ modules – what are the packaging considerations? In order to answer this question, we should first have a look at how the compiler resolves an import in the first place by trying to compile the “Hello, World!” example above:

clang++ -std=c++20 -o hello_world.cpp.o -c hello_world.cpp
hello_world.cpp:1:8: fatal error: module ‘fmt’ not found
import fmt;
~~~~~~~^~~
1 error generated.

In order to resolve import fmt, the compiler needs to locate the binary module interface (BMI) for the module named fmt. BMIs are files that are generated in addition to object files, and encodes the information for the exported declarations. For clang, we need to tell the compiler where this file is for this named module, in this case with the -fmodule-file=fmt=/path/to/fmt.pcm flag. Note that there are other flags and mechanisms for the compiler to locate modules, and these vary per compiler (see GCC, msvc). For illustration purposes, an example of a module interface could be:

fmt.cc (illustration only!):

export module fmt;

export namespace fmt {
void print(const char*);
}

Here’s where the workflow differs significantly from good old header files:

The binary module interfaces need to be generated (from the module interface units, in this case fmt.cc), ahead of the compilation of any importers. This introduces dependencies between C++ sources involved with modules.
BMIs are not compatible across compilers (they are implementation specific) and are also not expected to be compatible across different versions of the same compiler. Inconsistent compiler flags can also render a BMI invalid for the importer – that is, if the importer is being compiled with different (potentially incompatible) flags than when the BMI was first generated.

Solving the first problem (correct compilation order), has required giving the compilers the ability to scan source files for module dependencies and expressing them in a json file (see p1689r5). This information can then be used by the build system to derive the correct build order. CMake started experimenting with this earlier this year with version 3.25, and the feature will be available in the upcoming 3.28 release.

For the second problem, keep reading below!

Experimenting with packaged module libraries

With traditional libraries with header files, we know that the compiler needs to find the directory that contains the included files – either implicitly (by placing the header files in locations the compiler already searches), or explicitly (via -I flags). These days, build system abstractions around the usage of libraries mean that developers don’t have to manually pass these to the compiler. For example, Conan models the package information for consumers in the package_info() method. For C++ in particular, this is captured in the cpp_info attribute. Conan then uses this information when generating the specific build system integrations.

Note: the code for these experiments is available on GitHub.

Packaging the BMIs (don’t do it!)

While compiler documentation around C++ modules specify that BMIs are only compatible for the same compiler, compiler version and flags – we could take advantage of the Conan binary package model and package the BMIs alongside the binary libraries.

For compilers like Clang and msvc that allow passing flags to specify the location of the BMIs for specific named modules, we can rely on existing abstractions to propagate this information to the consumer, for example – in the package_info() method of a Conan recipe (full recipe here):

if is_msvc(self):
bmi_dir=os.path.join(self.package_folder, “bmi”).replace(‘\’,’/’)
self.cpp_info.cxxflags=[“/reference fmt=fmt.cc.ifc”, f”/ifcSearchDir{bmi_dir}”]
elif self.settings.compiler==”clang”:
self.cpp_info.cxxflags=[f”-fmodule-file=fmt={self.package_folder}/bmi/fmt.pcm”]

While the package contents are roughly like this (for Clang on Linux):

|– bmi
| └– fmt.pcm
└– lib
└– libfmt.a

For this to work – we would need to use Conan in a way that enforces strict compatibility. A package like the above would only be compatible with that specific compiler and version. Rougly, this means ensuring that for Conan, a package compiled with GCC 13.1 is different and not compatible with one compiled with GCC 13.2, and that a package built with C++20 is different and not compatible with one built with C++ 23. In order to do this, we would have to:

Ensure the compiler.version setting specifies the exact version of the compiler, and not just the major version. For msvc, this also needs the compiler.update setting (see docs).

Disable the default logic shipped with Conan 2.0 for the compatibility plugin, which encodes the behaviour for considering other binary packages as compatible candidates (docs here).

Does this work? Well, yes! But there are scenarios where it didn’t work:

For a library such as {fmt} that is built with -fvisibility=hidden, Clang rejects a BMI when the importer does not have this flag enabled and is using the default visibility.
Clang will reject BMIs where the original source file does not exist in the local filesystem – this would make it impossible to build packages on one machine (e.g. CI) and consume it on another. For a lot of our users, this is a deal breaker. Strictly speaking, the importer only needs a BMI and not the original sources. But we need to take into account that the source files are still referenced by the compiler when reporting errors.
GCC does not currently support compiler flags to specify where the BMIs are for specific modules, but rather, it supports a global module mapper. While we could create this with Conan, we would still need to cooperate with the build system on the consumer side.

On the other hand, msvc appeard to be more forgiving and reusing the repackaged BMI appeared to work just fine in the scenarios we tested.

While this approach may be useful for teams that have a strict and total control of their dependencies, the exact compiler and compiler version used (in all environments!) – packaging BMIs is not something that we would recommend in order to use modules.

Packaging the module interfaces

From the above experiment, it is clear that we would need to package the module interface alongside the library binaries. From the packaging perspective, this isn’t too dissimilar from packaging a header file: it’s still text files with C++ source code.

We would go from this:

|– include/foo
| └– foo.hpp —> this is a header file
└– lib
└– libfoo.a

to the following:

└– lib
|– cxx
| └– foo.cppm —> this is a module interface (does `export module foo`)
└– libfoo.a

However, this changes everything on the consumer side. If we have a project that imports modules from external libraries, we now need full cooperation from our build system: it needs to be aware of the module interfaces, and the compiler needs to be invoked at the right time in order to produce the BMIs before the importers require them.

Support for C++ modules in IMPORTED targets has been implemented in the upcoming CMake 3.28 release – you can see an experiment here where this is working using CMake’s generated fmt-config.cmake and fmt-targets.cmake.

CMake now includes this information if an exported target also has modules:

add_library(fmt::fmt SHARED IMPORTED)

# …

target_sources(fmt::fmt
INTERFACE
FILE_SET “fmt_module”
TYPE “CXX_MODULES”
BASE_DIRS “${_IMPORT_PREFIX}/lib/cxx/miu”
FILES “${_IMPORT_PREFIX}/lib/cxx/miu/src/fmt.cc”
)

So far, CMake 3.28 (still a Release Candidate at time of writing) is the only build system that implements dependency scanning and the ability to consume external libraries that provide modules, and the BMIs are built locally rather than distributed. A fairly modern setup is required as well! The compilers must support p1689r5 (Clang>=16.0, msvc from the 14.34 toolset, and the yet-to-be-released gcc 14), as well as the build tool (Ninja 1.11.1 or MSBuild). All very bleeding edge!

What’s next

We’re currently working on updating the cpp_info attribute to acommodate information pertaining to C++ modules, so that the Conan generators can include this for build systems with C++ Module support. In the case described here, this means CMake 3.28 initially. In the future, C++ module information will need to be expanded to inform the consumer which build flags or macro definitions should be used when producing the BMI. But today, hopefully this is useful to users who are currently eager to try out C++ modules, as more libraries start supporting them (see here for a list). This should only help and drive adoption!

Resources

“C++20 Modules: The Packaging and Binary Redistribution Story” (Cppcon 2023 slides)
Packaging libraries with C++ modules (experiments) – GitHub repository

>>> Read full article>>>
Copyright for syndicated content belongs to the linked Source : Hacker News – https://blog.conan.io/2023/10/17/modules-the-packaging-story.html

Tags: Modulespackagingtechnology
Previous Post

Leica announces ZM11 watch inspired by play of light shadow

Next Post

Higher Quality Random Floats

Dismissing politics as ‘dirty’ is wrong and self-defeating – The Republic News

Why Calling Politics ‘Dirty’ Is a Mistake That Holds Us All Back

December 21, 2025
Opinion — Eric Sorenson, Brett Engstrom, and Liz Thompson: We need more wild forests and ecological forestry. – VTDigger

Why We Must Protect and Expand Wild Forests Through Ecological Forestry

December 21, 2025
Scientists at the American Museum of Natural History discovered more than 70 new species in 2025 – Phys.org

Discover Over 70 Thrilling New Species Uncovered in 2025 by Top Scientists

December 21, 2025
The science of snowflakes – W&M News

The science of snowflakes – W&M News

December 21, 2025
Vietnam: Creating a green lifestyle with remote growing, vegetable boxes – Hortidaily

Vietnam Embraces Green Living with Remote Gardening and Fresh Vegetable Boxes

December 21, 2025
Technology is powerful but unforgiving when misused – Supreme Court judge warns – GhanaWeb

Supreme Court Judge Issues Stark Warning: Technology’s Power Can Be Dangerous When Misused

December 21, 2025
Georgia vs. Ole Miss set for Sugar Bowl: Preview and odds for CFP quarterfinal – CBS Sports

Georgia vs. Ole Miss Sugar Bowl Showdown: Exciting Preview and CFP Quarterfinal Odds

December 21, 2025
Consciousness breaks from the physical world by keeping the past alive – IAI TV

Consciousness breaks from the physical world by keeping the past alive – IAI TV

December 21, 2025
Charting the Global Economy: ECB, UK, BOJ Diverge on Rate Moves – Bloomberg.com

Global Economy in Flux: How the ECB, UK, and BOJ Are Diverging on Interest Rates

December 21, 2025
WildBrain Sells Stake in Peanuts Holdings to Sony Pictures Entertainment – Licensing International

WildBrain Sells Stake in Peanuts Holdings to Sony Pictures Entertainment – Licensing International

December 21, 2025

Categories

Archives

December 2025
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
293031  
« Nov    
Earth-News.info

The Earth News is an independent English-language daily published Website from all around the World News

Browse by Category

  • Business (20,132)
  • Ecology (980)
  • Economy (998)
  • Entertainment (21,875)
  • General (18,866)
  • Health (10,038)
  • Lifestyle (1,011)
  • News (22,149)
  • People (1,005)
  • Politics (1,013)
  • Science (16,214)
  • Sports (21,499)
  • Technology (15,981)
  • World (987)

Recent News

Dismissing politics as ‘dirty’ is wrong and self-defeating – The Republic News

Why Calling Politics ‘Dirty’ Is a Mistake That Holds Us All Back

December 21, 2025
Opinion — Eric Sorenson, Brett Engstrom, and Liz Thompson: We need more wild forests and ecological forestry. – VTDigger

Why We Must Protect and Expand Wild Forests Through Ecological Forestry

December 21, 2025
  • About
  • Advertise
  • Privacy & Policy
  • Contact

© 2023 earth-news.info

No Result
View All Result

© 2023 earth-news.info

No Result
View All Result

© 2023 earth-news.info

Go to mobile version