KhronosGroup / KhronosGroup/glslang

Compilation issues inside a C++ module

Open
#4,176 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
3.6k
Forks
989
Avg merge
1d 2h
Merged PRs (30d)
31

Description

I can't compile when glslang is used inside a (C++20) module. This is my module implementation unit:
```cpp
module;
#include
#include
#include

module ShaderCompiler;
import std;
```

This is a situation where standard library (std) is both `included` and `imported`, which yields a lot of redefinition errors, see error list:
```
xstring(2323, 52): [C2572] 'std::basic_string': redefinition of default argument: parameter 1
xstring(2323, 87): [C2572] 'std::basic_string': redefinition of default argument: parameter 2
vector(435, 49): [C2572] 'std::vector': redefinition of default argument: parameter 1
xtr1common(47, 47): [C2572] 'std::enable_if': redefinition of default argument: parameter 1
xstring(896, 52): [C2572] 'std::basic_string_view': redefinition of default argument: parameter 1
iosfwd(190, 52): [C2572] 'std::basic_stringbuf': redefinition of default argument: parameter 1
[...]
```

I guess this means that with modularized C++, one must use the C interface of glslang.?

### EDIT
Even when I use the C interface (I downloaded a compiled Window release), it seems the lib files (`glslang.lib`, `SPIRV.lib`, etc.) were compiled in a manner incompatible with my modularized build, I get some nasty linking errors:
```
Error LNK2038 : mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in MyProject.lib(std.ixx.obj)
Error LNK2038 : mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in MyProject.lib(std.ixx.obj)
[...]
```

I unfortunately don't have any experience with porting existing libraries to C++ modules, so it would seem I have to use an approach similar to GLM (https://github.com/g-truc/glm/blob/master/glm/glm.cppm), or compile everything from source by manually converting every single glslang header file into a module interface unit.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the shown module implementation unit and the ResourceLimits.h, ShaderLang.h, and GlslangToSpv.h headers, then compare it with the C interface and downloaded Windows libraries. Done should establish whether glslang supports this C++20 module setup and identify the compatible library/build configuration or document the limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.