6

I am trying to let xmake support gcc-11 to build c++20 modules, but I have some problems.

gcc-11 will generate the gcm.cache directory in the current directory by default. How can I modify this default path to the specified other directory?

I know that clang has a -fmodules-cache-path= option to modify the cache path of modules, but I did not find a similar option for gcc.

Does anyone know? thanks

asked Oct 13, 2021 at 3:09
2
  • 1
    I have not been able to find it. There is nothing in the man-page for g++, neither is it mentioned in their modules documentation. So I assume (at least for the moment) that it is not possible. Hopefully, they will add it one day. Commented Oct 17, 2021 at 14:16
  • Read this page: gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Module-Mapper.html You'd have to create your own "module-mapper" to make this work. I have my own custom build environment, so I'm thinking of a super simple program that reads all of your source, and creates the module-map file, and supplies it as an environment variable. Commented Nov 20, 2021 at 22:38

1 Answer 1

8

This worked for me gcc-11 on ubuntu 22.04 (Makefile fragment):

MAPPER_DIR := /path/to/obj/dir
CXXFLAGS += -fmodules-ts '-fmodule-mapper=|@g++-mapper-server -r'$(MAPPER_DIR)

The caveat I ran into is that g++-mapper-server won't create the root directory, so make sure its created first. You'll still have to work out dependencies so that the gcm is created/updated before the importing code is compiled.


The explanation is | invokes a mapper process via pipe, @ resolves the process name from the gcc tools directory (cf gcc manual). The -r option sets the root directory. Take care protecting the spaces and the | from make and shell.

The default mapper server takes arguments - you can tweak and play with it - here's the options on my version:

$ /usr/lib/gcc/x86_64-linux-gnu/11/g++-mapper-server --help
Usage: g++-mapper-server [OPTION...] [CONNECTION] [MAPPINGS...] 
C++ Module Mapper.
 -a, --accept Netmask to accept from
 -f, --fallback Use fallback for missing mappings
 -h, --help Print this help, then exit
 -n, --noisy Print progress messages
 -1, --one One connection and then exit
 -r, --root DIR Root compiled module directory
 -s, --sequential Process connections sequentially
 -v, --version Print version number, then exit
Send SIGTERM(15) to terminate
For bug reporting instructions, please see:
<file:///usr/share/doc/gcc-11/README.Bugs>.
answered Nov 6, 2022 at 1:46
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I have supported it using module mapper. github.com/xmake-io/xmake/blob/…

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.