A (Short) Tour of C++ Modulesnovice) employed by 3OVERVIEW Modules Foundations C++20 Modules, a short recap Module unit types and Module composition Visibility of Identifiers vs. Reachability of Declarations Relationships discarded discarded some header.hsource.cpp translation unit object file export module library; library interface unit module library; library implementation library implementation object file import commandline none module interface unit files object file BMI file discarded 7 . 2// mod.h #pragma once; struct S { int value = 1; } 1 2 3 4 5 6 module purview global module fragment module declaration0 码力 | 62 页 | 4.20 MB | 6 月前3
C++20 Modules: The Packaging and Binary Redistribution StoryC++ modules and their advantages ● Focus on named modules ● Using modules today ○ Can we package module-ready libraries and use them in our projects?The include directive ● Include directive: “Tells the clang++ -std=c++20 -o hello_world.cpp.o -c hello_world.cpp hello_world.cpp:1:8: fatal error: module 'fmt' not found import fmt; ~~~~~~~^~~ 1 error generated. #includeint main() { short: better isolation - some advantages to headers: ● Importers cannot affect the contents of the module being imported ● Imported modules cannot affect the state of the preprocessor in the importing 0 码力 | 76 页 | 2.09 MB | 6 月前3
C++ Modules: Getting Started TodayHello Modules! — File: module.cpp export module my_module; export char const* my_function () { return "Hello Modules!"; } — File: main.cpp #includeimport my_module; int main () { std:: println("{}" no_internal_linkage (); }14/50 Exporting things — File: module1.cpp export module A; export int foo() { return 42; } — File: module2.cpp export module B; export import A; — File: main.cpp import B; int int main () { return foo (); }15/50 Not exported does not mean unreachable — File: module.cpp export module m; class NotExported { int i = 42; }; export NotExported getNotExported () { return {}; 0 码力 | 65 页 | 1.97 MB | 6 月前3
Mastering C++ ModulesUnits" From C++ Now 20239 Ask ChatGPT 202310 Ask ChatGPT 2024Simple Module 11 export module B; export void b() { }Built Module Interface (BMI) • MSVC – .ifc file • G++ – .gcm file • Clang – cpp: export module B; export void b() { } A.cpp: export module A; import B; export void a(){ b();} cl -std:c++20 -interface -c A.cpp A.cpp A.cpp(2): error C2230: could not find module 'B' A.cpp(3): identifier not foundSimple Example (build order matters) 14 B.cpp: export module B; export void b() { } A.cpp: export module A; import B; export void a(){ b();} cl -std:c++20 -interface -c B.cpp B0 码力 | 77 页 | 9.07 MB | 6 月前3
Implementing C++ Modules: Lessons Learned, Lessons AbandonedStroustrup: ▪ “Every single word about “token comparison” is there to workaround absence of a real module system" ▪ Safety: – A toolchain should try its best to diagnose ODR violations ▪ e.g. linker call to its definition begins “the great hunt” (C) Dos Reis & DaCamara; CppCon 2021 6The Global Module ▪ Everything we used to do before Modules – Merry mess ▪ Provide no ODR guarantees – Responsibility CppCon 2021Module Ownership 8 (C) Dos Reis & DaCamara; CppCon 2021Module Ownership ▪ Supporting programming in the large (componentization) – Non-interference between module-local entities (module linkage)0 码力 | 53 页 | 1.33 MB | 6 月前3
Conan 2.5 Documentationio/en/stable/, or https://pypi.org/project/virtualenvwrapper-win/ in Windows) With Python 3, the built-in module venv can also be used instead (check https://docs.python.org/3/ library/venv.html). If not using a very simple C++ language project with this structure: . MODULE.bazel conanfile.txt main BUILD demo.cpp This project contains a MODULE.bazel file loading the Conan dependencies (in this case only Package Manager!\n", "Conan"); return EXIT_SUCCESS; } Listing 23: MODULE.bazel load_conan_dependencies = use_extension("//conan:conan_deps_module_extension.bzl", ˓→"conan_extension") use_repo(load_conan_dependencies0 码力 | 769 页 | 4.70 MB | 1 年前3
Conan 2.4 Documentationio/en/stable/, or https://pypi.org/project/virtualenvwrapper-win/ in Windows) With Python 3, the built-in module venv can also be used instead (check https://docs.python.org/3/ library/venv.html). If not using a very simple C++ language project with this structure: . MODULE.bazel conanfile.txt main BUILD demo.cpp This project contains a MODULE.bazel file loading the Conan dependencies (in this case only Package Manager!\n", "Conan"); return EXIT_SUCCESS; } Listing 23: MODULE.bazel load_conan_dependencies = use_extension("//conan:conan_deps_module_extension.bzl", ˓→"conan_extension") use_repo(load_conan_dependencies0 码力 | 769 页 | 4.69 MB | 1 年前3
Conan 2.6 Documentationio/en/stable/, or https://pypi.org/project/virtualenvwrapper-win/ in Windows) With Python 3, the built-in module venv can also be used instead (check https://docs.python.org/3/ library/venv.html). If not using a very simple C++ language project with this structure: . MODULE.bazel conanfile.txt main BUILD demo.cpp This project contains a MODULE.bazel file loading the Conan dependencies (in this case only Package Manager!\n", "Conan"); return EXIT_SUCCESS; } Listing 23: MODULE.bazel load_conan_dependencies = use_extension("//conan:conan_deps_module_extension.bzl", ˓→"conan_extension") use_repo(load_conan_dependencies0 码力 | 777 页 | 4.91 MB | 10 月前3
Conan 2.7 Documentationio/en/stable/, or https://pypi.org/project/virtualenvwrapper-win/ in Windows) With Python 3, the built-in module venv can also be used instead (check https://docs.python.org/3/ library/venv.html). If not using a very simple C++ language project with this structure: . MODULE.bazel conanfile.txt main BUILD demo.cpp This project contains a MODULE.bazel file loading the Conan dependencies (in this case only Package Manager!\n", "Conan"); return EXIT_SUCCESS; } Listing 23: MODULE.bazel load_conan_dependencies = use_extension("//conan:conan_deps_module_extension.bzl", ˓→"conan_extension") use_repo(load_conan_dependencies0 码力 | 779 页 | 4.93 MB | 10 月前3
Conan 2.10 Documentationio/en/stable/, or https://pypi.org/project/virtualenvwrapper-win/ in Windows) With Python 3, the built-in module venv can also be used instead (check https://docs.python.org/3/ library/venv.html). If not using a very simple C++ language project with this structure: . MODULE.bazel conanfile.txt main BUILD demo.cpp This project contains a MODULE.bazel file loading the Conan dependencies (in this case only Package Manager!\n", "Conan"); return EXIT_SUCCESS; } Listing 23: MODULE.bazel load_conan_dependencies = use_extension("//conan:conan_deps_module_extension.bzl", ˓→"conan_extension") use_repo(load_conan_dependencies0 码力 | 803 页 | 5.02 MB | 10 月前3
共 121 条
- 1
- 2
- 3
- 4
- 5
- 6
- 13













