fsb4000

modules example

Apr 17th, 2021 (edited)
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. gcc example:
  2.  
  3. ```
  4. import <iostream>;
  5.  
  6. int main()
  7. {
  8. std::cout << "Hello modules!\n";
  9. return 0;
  10. }
  11. ```
  12.  
  13. https://i.imgur.com/Y0gR8p7.png
  14.  
  15. g++ -std=c++20 -fmodules-ts -x c++-system-header iostream
  16.  
  17. g++ -std=c++20 -fmodules-ts main.cpp -o hello
  18.  
  19. clang++ -std=c++20 -stdlib=libc++ -fmodules -fbuiltin-module-map main.cpp -o hello
  20.  
  21.  
  22. Here steps with MSVC:
  23.  
  24. 1. Install 16.10 Preview 2
  25.  
  26. 2. enter some code with header units.
  27.  
  28. My example:
  29. ```
  30. import <iostream>;
  31. import <vector>;
  32.  
  33. int main()
  34. {
  35. std::vector v{1,2,3};
  36. std::cout << "Hello modules!\n";
  37. return static_cast<int>(v.size());
  38. }
  39. ```
  40.  
  41. 3. Open command promt for Visual Studio 2019 Preview.
  42.  
  43. 4. Compile header units which you use.
  44.  
  45. for iostream:
  46.  
  47. cl /EHsc /nologo /W4 /std:c++latest /MD /exportHeader /headerName:angle iostream /Fo:iostream.obj
  48.  
  49. for vector:
  50.  
  51. cl /EHsc /nologo /W4 /std:c++latest /MD /exportHeader /headerName:angle vector /Fo:vector.obj
  52.  
  53. 5. Compile example:
  54.  
  55. cl /EHsc /nologo /W4 /std:c++latest /MD /headerUnit:angle "iostream=iostream.ifc" /headerUnit:angle "vector=vector.ifc" main.cpp iostream.obj vector.obj
  56. main.cpp
  57.  
  58. Real screenshot:
  59.  
  60. https://i.imgur.com/WElKYjo.png
Add Comment
Please, Sign In to add comment