icmodmap(1) | initializes C++ projects using modules | icmodmap(1) |
icmodmap - Initializes the maintenance of C++ projects using modules
icmodmap [Options] start-directory
Although modules have already been available for quite some time, the gnu g++ compiler still shows a number of bugs related to C++ modules (cf. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103524). So it’s possible that when using modules you will encounter some of these (or new) bugs. The bugs will probabably have been repaired in future releases of the compiler, and the current state of affairs at least allows you to gain some experience in using modules.
Modules cannot mutually import each other. Consequently there’s always a linear, non-circular module hierarchy, which should be acknowledged when compiling files defining and using modules. The icmodmap program determines this order and prepares the construction of modules used by programs.
Icmodmap assumes that modules are defined in separate sub-directories, and that module interfaces are defined in (by default) files named module.cc. If a program defines two modules First and Second (e.g., in sub-directories first and second and the second/module.cc imports module First then first/module.cc must be compiled before compiling second/module.cc. This is handled by icmodmap. Once the module.cc files have been compiled the remaining source files of the program can be compiled as usual.
Icmodmap expect projects using modules to be organized as follows:
Icmodmap(1) inspects each specified sub-directory. If it contains the file module.cc (or its alternative name), then that file (having the following structure) is inspected:
Icmodmap supports the following options:
Square:l DepSquare: Squarehere, the :l suffix indicates that Square is a module defined by the project, not depending on other modules. When module definitions do depend on other modules they’re listed next: DepSquare is another module defined by the project, depending on the Square module.
Square:e Mod1: Square:e Mod2: Square:e Mod1 Mod3: Square:e Mod1 Mod2In this example module Square is an external module, indicated by the :e suffix. All other modules depend on Square, and (e.g.,) Mod3 also depnds on the locally defined modules Mod1 and Mod2. In this latter example the Square.gcm file must be available in the project’s gcm.cache directory (it could be a soft-link to the actual file);
The following program defines a module Square in its sub-directory square, containing this module.cc file:
export module Square; export { double square(double value); class Square { double d_amount; public: Square(double amount = 0); // initialize void amount(double value); // change d_amount double amount() const; // return d_amount double lastSquared() const; // returns g_squared double square() const; // returns sqr(d_amount) }; } double g_squared;
The main function imports the Square module and uses its facilities. It also imports the iostream module-compiled system header. That header is not inspected by icmodmap, and must be available before the main.cc file can be compiled. Here is the main.cc source file:
import Square; import <iostream>; int main(int argc, char **argv) { std::cout << "the square of " << argc << " is " << square(argc) << ’\n’; Square obj{12}; std::cout << "the square of 12 is " << obj.square() << "\n" "the last computed square is " << obj.lastSquared() << ’\n’; }
Executing icmodmap -d . shows Square as a local module:
Square:l
Executing icmodmap -V . shows the compilation of square/module.cc:
Module: Square square: /bin/g++ --std=c++26 -fdiagnostics-color=never -c -fmodules-ts -Wall -o ../tmp/o/1module.o module.cc
It also defines the gcm.cache subdirectory, containing Square.gcm and a soft-link usr -> /usr, and because of this soft-link the compiler finds the module-compiled system header files. It also defines the soft-link square/gcm.cache -> ../gcm.cache: those soft-links are defined in all sub-directories used by the program, allowing all source files in all of the program’s sub-directories to import all modules defined in the main directory’s gcm.cache directory.
icmake(1).
None reported.
This is free software, distributed under the terms of the GNU General Public License (GPL).
Frank B. Brokken (f.b.brokken@rug.nl).
1992-2025 | icmake.13.00.03 |