-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
VS 2022 17.5 Preview 1 and std module #3195
Comments
I just added the std.ixx file directly to my project, I didn't need a separate library. I'll cheekily add my question here. If i do
should I expect it to work? |
@davidhunter22 Assuming you meant
which now fails to compile: |
Thanks @matbech I updated my question |
@davidhunter22 , probably it should work, but the compiler has bugs. |
One sad thing I noticed with adding the .ixx file to a project. If you have a solution with 200 projects and all of them add the .ixx file then you compile the standard library module 200 times. This does only happen on the first build but :-( |
Not being able to mix "import std" with classic includes is a real pain. Any large body of code these days probably uses third party libraries, in my case from vcpkg. Almost all of them will #include standard library header in their headers. So you can't migrate your code to use import std until every library you depend on either has a build varaint that uses the std module or has a macro to guard #includes in it's headers. As in
|
I believe using a static library (add the std.ixx) which is then referenced by the other projects in your solution is the right approach. For the mixed headers issue, I hope @StephanTLavavej can provide some guidance. |
Thanks for trying to use the Standard Library Modules as soon as possible! 😻 We're still working on adding build system support so Answering specific questions/topics (please let me know if I missed anything; thanks @fsb4000 for quoting an earlier reply of mine from Discord):
|
I have a work around for including third party libraries that then do old style #includes of standard library headers. If you have the tiniest shred of dignity you may want to look away now. So the MS standard library headers still use old style macro include guards not #pragma once. So you can simply define all these macro guards yourself and then include the header file that does things like "#include ". Attached is a header that defines all the ones I think you need. Oddly you can't upload .h files so I renamed it to .txt |
This does not work at all. If you define the guards then any C++ headers won't get included and the 3rd party headers which require those will not compile. E.g.
atlbase.h includes <type_traits> which won't get included because of the define in MacroGuards.h. |
I am including the headers in my code which has an "import std;" so all the standard library types are aready declared before I include the third party header. I should have mentioned you need to do
I am already using this successfully for a number of libraries, such as type_safe, pugxml and catch2 that I use via vcpkg without modfiying them in any way. |
It doesn't work for me when importing the std module in a precompiled header (e.g. pch.h) and I do include the 3rd party libraries there. |
Ah good point. I switched off pch stuff in my build before trying this out mostly because I feel the standard library module is sort of a replacement for a PCH containing the standard library stuff. If you have PCH files including third party library stuff that then include standard library stuff I am well out of my depth! I am sure there are other corner cases where this hackery does not work but as I said it does work for reasonably complex headers like those from catch2 |
Instead of defining our preprocessor guard macros to suppress classic includes, there's a less-wacky (still fairly wacky) technique that may work: create a bunch of fake headers named |
I have given this a try, however without success. The compiler gets confused after it encounters an import std; statement in the PCH and it will start throwing errors like:
for code which compiles fine otherwise: #include "pch.h"
import std;
int main()
{
std::vector<int> test;
test.resize(5);
} pch.h #pragma once
// All CRT headers must be included before the first import statement
#include <crtheaders.h>
import std; |
This problem was found in trying to build the google_test library with the std module I found a specific issue of mixing the
which then causes a type redefinition error. Ideally the |
Automatic MSBuild suuport was implemented with "Scan Sources for Module Dependencies". |
Great! |
@MikeGitb If I get it right it's already there - Project properties -> C/C++ -> General -> Scan Sources for Module Dependencies |
Thx, will have a look during the weekend. Edit: Can confirm with 17.7.4 - great stuff. Thanks. |
What should I do to use this in CMake? |
Something like this worked for me: std/CMakeLists.txt
myproject/CMakeLists.txt
|
As per the Changelog, Standard Library Module std is available in VS 2022 17.5 Preview 1. Is there something special that needs to be done as it doesn't seem to be working out of the box. I'm getting the following compile error when importing std:
error C2230: could not find module 'std'
with /experimental:module
The "V143 modules (experimental)" individual feature is installed as well.
Importing the legacy std.core module works without any errors though.
I got it working by creating a new C++ static library project, then I added the std.ixx module file from the modules folder:
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32019\modules
$(VCToolsInstallDir)modules\std.ixx
and then I referenced this new project.
Is there another way?
The text was updated successfully, but these errors were encountered: