У меня есть небольшой заголовок библиотеки, предназначенный для простого включения с помощью препроцессора. Но я также хочу, чтобы кто-нибудь скомпилировал его в модуль. Как я предполагаю, теперь я могу просто добавить несколько строк, которые требуются модулям, и они будут игнорироваться, если не скомпилированы в модуль. Я создал интерфейс .ixx, но при попытке компиляции возникли ошибки.
The iscstdlibc++.h
/**
* This is some std library contains some common declarations.
*/
export module iscstdlibcpp;
#ifndef _ISC_STD_LIB
#define _ISC_STD_LIB
//#define _ISC_STD_LIB_CPP
//#if defined(__cpp_modules) && (defined(__clang_modules_build) || //defined(__cplusplus_modules) || defined(MODULE))
//#define
//#endif
#include
#include
#include
#include
#include
#include
#include
#include
/**
* @brief For the C++ here are common class declarations and structures
*
*/
namespace ISC_STD {
// my header declaratioms
} // namespace __ISC_STD
#endif // ISC_STD_LIB_CPP
Файл .ixx такой же, за исключением того, что содержит только объявления
/**
* This is some std library contains some common declarations.
*/
export module iscstdlibcpp;
#include
#include
#include
#include
#include
#include
#include
#include
/**
* @brief For the C++ here are common class declarations and structures
*
*/
namespace ISC_STD {
// like in header but only declarations without the code
} // namespace __ISC_STD
пробовал скомпилировать с помощью команды (я использую Windows):
PS C:\programming\ISC\lib> clang++ iscstdlibc++.h -std=c++23 -c -Xclang -emit-module-interface iscstdlibc++.ixx -o iscstdlibcpp.pcm
clang++: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang++: warning: iscstdlibc++.ixx: 'linker' input unused [-Wunused-command-line-argument]
In file included from iscstdlibc++.h:11:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.39.33519\include\map:8:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.39.33519\include\yvals_core.h:501:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.39.33519\include\vcruntime.h:58:
In file included from C:\cclang\clang\LLVM\lib\clang\17\include\vadefs.h:18:
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.39.33519\include\vadefs.h:155:18: error: declaration of '__va_start' in the global module follows declaration in
module iscstdlibcpp
155 | void __cdecl __va_start(va_list* , ...);
| ^
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.39.33519\include\vadefs.h:155:18: note: previous declaration is here
In file included from iscstdlibc++.h:11:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.39.33519\include\map:11:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.39.33519\include\tuple:13:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.39.33519\include\__msvc_iter_core.hpp:10:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.39.33519\include\utility:22:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.39.33519\include\cstdlib:12:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\stdlib.h:311:22: error: declaration of '_rotl' in the global module follows declaration in module iscstdlibcpp
311 | unsigned int __cdecl _rotl(
| ^
// just c++ std lib flow ...
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
Подробнее здесь: https://stackoverflow.com/questions/786 ... -as-module