-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[C++20][Modules] Clang ignores #pragma comment(lib, ...)
directives
#61733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@llvm/issue-subscribers-clang-modules |
Generally clang doesn't support the comment lib pragma, in modules or not - you'd need to pass the relevant linker flag to link the library. I don't think this is a uniquely modular bug/a fairly generic clang-cl feature request. |
#pragma comment
directives#pragma comment(lib, ...)
directives
Clang does support the comment pragma. I've never had to manually specify the MSVC runtime libraries to a linker. Here is the commit that added support for it. And here is the related issue. |
Oh, thanks for the context - I didn't realize/went looking for an existing issue. Yeah, so maybe this is modules-specific, then. Perhaps we don't serialize the pragma properly. |
we do not do anything special for C++20 modules w.r.t pragmas, so I'd guess that this problem would also show with PCH? |
Oh, this is related to eager loading. Let me try to handle this. |
I've done a quick test here and the pragma does work with precompiled headers. |
The direct cause for the issue is that I banned the eagerly loading for declarations from named modules to speedup the process of reading modules (See #61064 for example). I thought it makes sense because the mechanism to load declarations eagerly is designed for header modules. But I didn't think about PragmaCommentDecl and PragmaDetectMismatchDecl. So here is the issue. Note that the inconsistency to load declarations from named modules is still problematic. See #61783 for example. I reverted the previous patch since I feel it is more important to not break the user's code than compilation speed. I'll try to handle this properly before the release of 17. |
Module version:
Non module version:
In the module version there's no
/DEFAULTLIB:msvcprt.lib
attribute. The MSVC STL uses#pragma comment
to attach linker flags to object files, so that at linking time the right set of flags/libraries are used.If something like
<optional>
is used, there's no problem, but if<iostream>
(there's others as well) is used for example, we'll get a lot of unresolved symbol errors from the linker, because we're not linking the right libraries (msvcprt.lib in this case).The directive
#pragma detect_mismatch
(and possibly others) is also being ignored by Clang when building modules.The text was updated successfully, but these errors were encountered: