[build2] C++ modules: how to generate the modules-list for own library

Wilhelm Meier wilhelm.meier at hs-kl.de
Tue May 9 11:05:29 UTC 2023


Actually I'm using the following buildfile:
---
config.cxx = /usr/local/bin/avr-g++

cxx.std = experimental
cxx.features.modules = true

config.cxx.target = avr-none-none

using cxx

assert $cxx.features.modules "no modules support for $cxx.signature"

mxx{*}: extension = mpp
cxx{*}: extension = cc

exe{test00}: cxx{test00}

cxx.modules = std=../../../include/std/std.mpp \
std:array=../../../include/std/array.mpp \
std:cstdint=../../../include/std/cstdint.mpp
---

All module interface units are *.mpp file in the
directory ../../../include/std/.

The main TU is in test00.cc:
---
import std;

int main() {
     std::array<int, 3> arr;
}
---

This gives the following errors:

[...]
/usr/local/bin/avr-g++ -std=c++23 -fmodules-ts -finput-charset=UTF-8 -E 
-x c++ -fpreprocessed -fdirectives-only 
/home/lmeier/Projekte/wmucdoc/src/boards/protoboard/tests/test00.o.ii
/usr/local/bin/avr-g++ -std=c++23 -fmodules-ts -fdiagnostics-color 
-finput-charset=UTF-8 -fmodule-mapper=test00.o.d?@ -o test00.o -c -x c++ 
-fpreprocessed -fdirectives-only 
/home/lmeier/Projekte/wmucdoc/src/boards/protoboard/tests/test00.o.ii
/home/lmeier/Projekte/wmucdoc/src/boards/protoboard/tests/test00.cc:1:1: 
error: unknown Compiled Module Interface: no such module
1 | import std;
| ^~~~~~
In module imported at 
/home/lmeier/Projekte/wmucdoc/src/boards/protoboard/tests/test00.cc:1:1:
std: error: failed to read compiled module: Unknown CMI mapping
std: note: imports must be built before being imported
std: fatal error: returning to the gate for a mechanical issue
compilation terminated.
error: process /usr/local/bin/avr-g++ exited with code 1
info: while updating 
/home/lmeier/Projekte/wmucdoc/src/boards/protoboard/tests/obje{test00.o}
info: while updating 
/home/lmeier/Projekte/wmucdoc/src/boards/protoboard/tests/exe{test00.}
info: while updating 
/home/lmeier/Projekte/wmucdoc/src/boards/protoboard/dir{tests/}
info: failed to update 
/home/lmeier/Projekte/wmucdoc/src/boards/protoboard/dir{tests/}


On 08.05.23 15:31, Boris Kolpackov wrote:
> Wilhelm Meier <wilhelm.meier at hs-kl.de> writes:
> 
>> I want to convert a own header-only library to a version using modules.
>> Because it is a header-only library (mostly templates) I'm using module
>> interface unit as *.cpp files in some directory structure. Seldom I split a
>> module in module-partitions with more than one *.cpp file.
>>
>> If I want to use this modules, the build-tool needs a mapping between module
>> names an the corresponding *.cpp files of our library.
> 
> Is this header-only library built with build2? If so, you (normally)
> don't need an explicit mapping. For example, if your module interface
> is in foo.cpp, then (normally) all you need is:
> 
> lib{foo}: mxx{foo.cpp}



More information about the users mailing list