Но чего-то нихрена не работет пока.
1. Windows 10
2. Компилятор С++ из состава msys64 = ucrt64
версия 14.2
__cpp_modules = 201810
Подключено в Code::Blocks 25.03
В родном инсталляторе тоже есть mingw64 с компилятором g++ 14.2
3. Вот здесь:
https://gcc.gnu.org/projects/cxx-status.html#cxx20
написано, что модули фактически поддерживаются с 11 версии.
4. Пробую пример из cppreference
Режимы компиляции
-std=c++20
-fmodules-ts -- без этого модули не транслируются
------------
файл HW.cpp
export module HW; // module declaration
import <iostream>; // import declaration
#include <iostream> // -- заменил
export void hello() // export declaration
{
std::cout << "Hello world!\n";
}
файл main.cpp
import HW; // import declaration
#include <iostream>
using std::cout;
int main()
{
cout << __cpp_modules <<'\n'; // >= 201810L
hello();
return 0;
}
Результат:
||=== Build: Release in modules (compiler: GNU GCC Compiler) ===|
Непонятки с модулем
failed to read compiled module||No such file or directory|
||note: compiled module file is 'gcm.cache/HW.gcm'|
||note: imports must be built before being imported|
||error: returning to the gate for a mechanical issue|
Конфликты со стандартными файлами
C:\msys64\ucrt64\include\c++\14.2.0\typeinfo|91|error: conflicting declaration of 'class std::type_info' in global module|
C:\msys64\ucrt64\include\c++\14.2.0\bits\cxxabi_init_exception.h|52|note: previously declared in module 'HW'|
C:\msys64\ucrt64\include\c++\14.2.0\bits\exception_ptr.h|54|error: conflicting declaration of 'class std::type_info' in global module|
C:\msys64\ucrt64\include\c++\14.2.0\bits\cxxabi_init_exception.h|52|note: previously declared in module 'HW'|
C:\msys64\ucrt64\include\c++\14.2.0\bits\cpp_type_traits.h|470|error: conflicting declaration of 'struct std::iterator_traits<_Iterator>' in global module|
C:\msys64\ucrt64\include\c++\14.2.0\bits\stl_iterator_base_types.h|177|note: previously declared in module 'HW'|
C:\msys64\ucrt64\include\c++\14.2.0\bits\memory_resource.h||In constructor 'std::pmr::polymorphic_allocator<_Tp>::polymorphic_allocator()':|
C:\msys64\ucrt64\include\c++\14.2.0\bits\memory_resource.h|135|error: block-scope extern declaration 'std::pmr::memory_resource* std::pmr::get_default_resource()' must not be attached to a named module|
C:\VVL\CppProjects\modules\HW.cpp|4|warning: not writing module 'HW' due to errors|
||=== Build failed: 6 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
Конфликты с моим модулем — он явно оттранслирован.
Но кк-то не для сборки.
Конфликты явно из-за include
импорт iostream , естественно, не работает
В принципе, для этого можно оттранслировать stl в виде модулей, но что потом ?
Куда смотреть ?
Или модули надо транслировать отдельно ?
Сложить их в некоторый каталог и прописать линкеру путь ?