c++ modules automatic dependency generation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





I try to use c++ module. For any real world project is is needed to get
the dependencies automatically.

If I use "old-style" include <bla>; include "blub" I simply can use g++
-M or g++ -MM.

If I use modules in my files, I have no idea how to get the deps for them.

Example project has two files:


f1.cpp
------------------------------
export module f1module;
import <iostream>;


export void f1()
{
    std::cout << "Check" << std::endl;
}
--------------------------------


and

main.cpp
--------------------------------
import <iostream>;
import <sstream>;
import f1module;


int main()
{
    std::ostringstream os;
    os << "Test";
    std::cout << os.str() << std::endl;
    f1();
}
------------------------------

> g++ -fmodules-ts -std=c++26 -c main.cpp -MD -MFmain.d -E>/dev/null

If I do that, I need to compile the system headers first. But in fact, I
want to determine them from running auto dep generation. Seems to be a
chicken and egg problem :-)

If I did not compile the system headers before, I got:


$ g++ -fmodules-ts -std=c++26 -c main.cpp -MD -MFmain.d -E>/dev/null
In module imported at main.cpp:1:1:
/usr/include/c++/14/iostream: error: failed to read compiled module: No
such file or directory
/usr/include/c++/14/iostream: note: compiled module file is
'gcm.cache/./usr/include/c++/14/iostream.gcm'
/usr/include/c++/14/iostream: note: imports must be built before being
imported
/usr/include/c++/14/iostream: fatal error: returning to the gate for a
mechanical issue
compilation terminated.

After I compile the headers from hand:
$g++ -std=c++26 -fmodules-ts -x c++-system-header iostream
$g++ -std=c++26 -fmodules-ts -x c++-system-header sstream

I see main.d with:
main.o: main.cpp /usr/include/stdc-predef.h \
 gcm.cache/./usr/include/c++/14/iostream.gcm \
 gcm.cache/./usr/include/c++/14/sstream.gcm
main.o: f1module.c++m /usr/include/c++/14/sstream.c++m \
 /usr/include/c++/14/iostream.c++m
CXX_IMPORTS += f1module.c++m /usr/include/c++/14/sstream.c++m \
 /usr/include/c++/14/iostream.c++m

Interestingly there is no problem to import f1module. This module was
not build before.

Is this a bug or a feature :-)

Maybe someone have a workaround?

Thanks!
 Klaus




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux