{"id":5912,"date":"2020-05-18T07:58:31","date_gmt":"2020-05-18T07:58:31","guid":{"rendered":"https:\/\/www.modernescpp.com\/index.php\/c-20-module-interface-unit-and-module-implementation-unit\/"},"modified":"2023-09-28T06:47:00","modified_gmt":"2023-09-28T06:47:00","slug":"c-20-module-interface-unit-and-module-implementation-unit","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/c-20-module-interface-unit-and-module-implementation-unit\/","title":{"rendered":"C++20: Module Interface Unit and Module Implementation Unit"},"content":{"rendered":"<p>Thanks to the module interface unit and implementation unit, you can separate the interface from the implementation when defining a module. Let me show you how.<\/p>\n<p><!--more--><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-8380 size-full\" style=\"display: block; margin-left: auto; margin-right: auto;\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/06\/TimelineCpp20Ranges.png\" alt=\"\" width=\"979\" height=\"373\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/06\/TimelineCpp20Ranges.png 979w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/06\/TimelineCpp20Ranges-300x114.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/06\/TimelineCpp20Ranges-768x293.png 768w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/06\/TimelineCpp20Ranges-705x269.png 705w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/06\/TimelineCpp20Ranges-845x321.png 845w\" sizes=\"auto, (max-width: 979px) 100vw, 979px\" \/><\/p>\n<p>As promised in my last post, <a href=\"https:\/\/bit.ly\/SimpleMathModul\">C++20: A Simple math Modul<\/a>, I want to make a short detour on my Clang Odyssee. My detour is a compact refresher to all I wrote in the referred post.<\/p>\n<h2>My Clang Odyssey<\/h2>\n<p>First, I don&#8217;t want to blame anyone but myself. Based on talks from Boris Kolpackov &#8220;<a href=\"https:\/\/github.com\/CppCon\/CppCon2017\/blob\/master\/Presentations\/Building%20C%2B%2B%20Modules\/Building%20C%2B%2B%20Modules%20-%20Boris%20Kolpackov%20-%20CppCon%202017.pdf\">Building C++ Modules<\/a>&#8221; at the CppCon 2017 or Corentin Jabot &#8220;<a href=\"https:\/\/cor3ntin.github.io\/posts\/modules\/\">Modules are not a tooling opportunity<\/a>&#8221; I had the impression that the vendors suggested the following extensions for their module definition:<\/p>\n<ul>\n<li>Windows: ixx<\/li>\n<li>Clang: cppm<\/li>\n<li>GCC: no suggestion<\/li>\n<\/ul>\n<p>In the case of the Clang compiler, I was wrong. This is my simple <span style=\"font-family: courier new, courier;\">math<\/span> module, which I tried to compile with the Clang compiler.<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ math.cppm<\/span>\n\n<span style=\"color: #006699; font-weight: bold;\">export<\/span> module math;\n\n<span style=\"color: #006699; font-weight: bold;\">export<\/span> <span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">add<\/span>(<span style=\"color: #007788; font-weight: bold;\">int<\/span> fir, <span style=\"color: #007788; font-weight: bold;\">int<\/span> sec){\n    <span style=\"color: #006699; font-weight: bold;\">return<\/span> fir <span style=\"color: #555555;\">+<\/span> sec;\n} \n<\/pre>\n<\/div>\n<p>I tried to compile the module with Clang 9 and Clang 10 on Microsoft and Linux. I tried to compile it with the brand-new Clang 11 compiler, built from the sources. Here is one of my many tries.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5910\" style=\"display: block; margin-left: auto; margin-right: auto;\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2020\/05\/ClangError.png\" alt=\"ClangError\" width=\"650\" height=\"166\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2020\/05\/ClangError.png 1300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2020\/05\/ClangError-300x77.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2020\/05\/ClangError-1024x262.png 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2020\/05\/ClangError-768x196.png 768w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>This command line should create the module<span style=\"font-family: courier new, courier;\"> math.pcm<\/span>. I specified in the command line <strong><span style=\"font-family: courier new, courier;\">-std=c++20 -fmodules-ts<\/span><\/strong> and the error message said: <span style=\"font-family: courier new, courier;\">module interface compilation requires &#8216;<strong>-std=c++20&#8242; or &#8216;-fmodules-ts&#8217;<\/strong><\/span>.\u00a0 I made all variations of the two flags, added the global module fragment to the module definition, and invoked the Clang compiler with additional flags, but the result was always the same.<\/p>\n<p>Then I asked Arthur O&#8217;Dwyer and Roland Bock for their help. For Arthur, modules worked fine with Clang: &#8220;<a href=\"https:\/\/quuxplusone.github.io\/blog\/2019\/11\/07\/modular-hello-world\/\">Hello World with C++2a modules<\/a>&#8220;. Roland rebuilt its Clang 11, and it worked with my module definition.<\/p>\n<p>Roland and I had the same Clang compiler and the exact module definition. I compared his command-line with mine, character by character, and I noticed something.<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\">Mine:   clang<span style=\"color: #555555;\">++<\/span> <span style=\"color: #555555;\">-<\/span>std<span style=\"color: #555555;\">=<\/span>c<span style=\"color: #555555;\">++<\/span><span style=\"color: #ff6600;\">20<\/span> <span style=\"color: #555555;\">-<\/span> <span style=\"color: #555555;\">-<\/span>fmodules<span style=\"color: #555555;\">-<\/span>ts <span style=\"color: #555555;\">-<\/span>stdlib<span style=\"color: #555555;\">=<\/span>libc<span style=\"color: #555555;\">++<\/span> <span style=\"color: #555555;\">-<\/span>c math.cppm <span style=\"color: #555555;\">-<\/span>Xclang <span style=\"color: #555555;\">-<\/span>emit<span style=\"color: #555555;\">-<\/span>module<span style=\"color: #555555;\">-<\/span>interface <span style=\"color: #555555;\">-<\/span>o math.pcm\nRoland: clang<span style=\"color: #555555;\">++<\/span> <span style=\"color: #555555;\">-<\/span>std<span style=\"color: #555555;\">=<\/span>c<span style=\"color: #555555;\">++<\/span><span style=\"color: #ff6600;\">20<\/span> <span style=\"color: #555555;\">-<\/span> <span style=\"color: #555555;\">-<\/span>fmodules<span style=\"color: #555555;\">-<\/span>ts <span style=\"color: #555555;\">-<\/span>stdlib<span style=\"color: #555555;\">=<\/span>libc<span style=\"color: #555555;\">++<\/span> <span style=\"color: #555555;\">-<\/span>c math.cpp <span style=\"color: #555555;\">-<\/span>Xclang <span style=\"color: #555555;\">-<\/span>emit<span style=\"color: #555555;\">-<\/span>module<span style=\"color: #555555;\">-<\/span>interface <span style=\"color: #555555;\">-<\/span>o math.pcm\n<\/pre>\n<\/div>\n<p>Roland gave his module\u00a0<span style=\"font-family: courier new, courier;\">math.cpp\u00a0<\/span><span style=\"font-family: 'courier new', courier;\">cpp<\/span>, and so did Arthur.<strong> Don&#8217;t give your module definition the suffix cppm<\/strong>.<\/p>\n<p>Now, compiling and using the module was straightforward.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5377\" style=\"display: block; margin-left: auto; margin-right: auto;\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/01\/clang.png\" alt=\"clang\" width=\"650\" height=\"119\" \/><\/p>\n<p>To end this Odyssey, here is the <span style=\"font-family: courier new, courier;\">client.cpp<\/span> file and a few words to the necessary flags for the Clang command line.<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ client.cpp<\/span>\n\nimport math;\n\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">main<\/span>() {\n   \n   add(<span style=\"color: #ff6600;\">2000<\/span>, <span style=\"color: #ff6600;\">20<\/span>);\n   \n}\n<\/pre>\n<\/div>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\">clang<span style=\"color: #555555;\">++<\/span> <span style=\"color: #555555;\">-<\/span>std<span style=\"color: #555555;\">=<\/span>c<span style=\"color: #555555;\">++<\/span><span style=\"color: #ff6600;\">2<\/span>a <span style=\"color: #555555;\">-<\/span>stdlib<span style=\"color: #555555;\">=<\/span>libc<span style=\"color: #555555;\">++<\/span> <span style=\"color: #555555;\">-<\/span>c math.cpp <span style=\"color: #555555;\">-<\/span>Xclang <span style=\"color: #555555;\">-<\/span>emit<span style=\"color: #555555;\">-<\/span>module<span style=\"color: #555555;\">-<\/span>interface <span style=\"color: #555555;\">-<\/span>o math.pcm  <span style=\"color: #0099ff; font-style: italic;\">\/\/ (1)<\/span>\nclang<span style=\"color: #555555;\">++<\/span> <span style=\"color: #555555;\">-<\/span>std<span style=\"color: #555555;\">=<\/span>c<span style=\"color: #555555;\">++<\/span><span style=\"color: #ff6600;\">2<\/span>a <span style=\"color: #555555;\">-<\/span>stdlib<span style=\"color: #555555;\">=<\/span>libc<span style=\"color: #555555;\">++<\/span> <span style=\"color: #555555;\">-<\/span>fprebuilt<span style=\"color: #555555;\">-<\/span>module<span style=\"color: #555555;\">-<\/span>path<span style=\"color: #555555;\">=<\/span>. client.cpp math.pcm <span style=\"color: #555555;\">-<\/span>o client   <span style=\"color: #0099ff; font-style: italic;\">\/\/ (2)<\/span>\n<\/pre>\n<\/div>\n<ol>\n<li>Creates the module <span style=\"font-family: courier new, courier;\">math.pcm<\/span>. The suffix <span style=\"font-family: courier new, courier;\">pcm<\/span> stands for the precompiled module. The flag combination<span style=\"font-family: courier new, courier;\"> -Xclang -emit-module-interface<\/span> is necessary for creating the precompiled module.<\/li>\n<li>Creates the executable <span style=\"font-family: courier new, courier;\">client<\/span>, which uses the module <span style=\"font-family: courier new, courier;\">math.pcm<\/span>. You have to specify the path to the module with the flag <span style=\"font-family: courier new, courier;\">-fprebuilt-module-p<\/span>ath.<\/li>\n<\/ol>\n<p>The module <span style=\"font-family: courier new, courier;\">math<\/span> was straightforward. Let&#8217;s be a bit more sophisticated.<\/p>\n<h2>Guideline for a Module Structure<\/h2>\n<p>Here is the first guideline for a module structure:<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\">module;                      <span style=\"color: #0099ff; font-style: italic;\">\/\/ global module fragment<\/span>\n\n<span style=\"color: #009999;\">#include &lt;headers for libraries not modularized so far&gt;<\/span>\n\n<span style=\"color: #006699; font-weight: bold;\">export<\/span> module math;          <span style=\"color: #0099ff; font-style: italic;\">\/\/ module declartion <\/span>\n\nimport <span style=\"color: #555555;\">&lt;<\/span>importing of other modules<span style=\"color: #555555;\">&gt;<\/span> \n\n<span style=\"color: #555555;\">&lt;<\/span>non<span style=\"color: #555555;\">-<\/span>exported declarations<span style=\"color: #555555;\">&gt;<\/span>  <span style=\"color: #0099ff; font-style: italic;\">\/\/ names with only visibiliy inside the module<\/span>\n\n<span style=\"color: #006699; font-weight: bold;\">export<\/span> <span style=\"color: #006699; font-weight: bold;\">namespace<\/span> math {\n\n    <span style=\"color: #555555;\">&lt;<\/span>exported declarations<span style=\"color: #555555;\">&gt;<\/span>  <span style=\"color: #0099ff; font-style: italic;\">\/\/ exported names <\/span>\n\n}\n<\/pre>\n<\/div>\n<p>This guideline serves two purposes. It gives you a simplified module structure and an idea of what I&#8217;m going to write about. So, what&#8217;s new in this module structure?<\/p>\n<ul>\n<li>You can import modules. The imported modules have module linkage and are not visible outside the module. This observation also applies to the non-exported declarations.<\/li>\n<li>I put the exported names in namespace <span style=\"font-family: 'courier new', courier;\">math<\/span>, which has the same name as the module.<\/li>\n<li>The module has only declared names. Let&#8217;s write about the separation of the interface and the implementation of a module.<\/li>\n<\/ul>\n<h2>Module Interface Unit and Module Implementation Unit<\/h2>\n<p>According to the mentioned guideline, I want to refactor the final version of module <span style=\"font-family: courier new, courier;\">math<\/span> from the previous post <a href=\"https:\/\/bit.ly\/SimpleMathModul\">C++20: A Simple math Modul.<\/a><\/p>\n<h3>Module Interface Unit<\/h3>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ mathInterfaceUnit.ixx<\/span>\n\nmodule;                   \n\nimport std.core;                            \n\n<span style=\"color: #006699; font-weight: bold;\">export<\/span> module math;       \n\n<span style=\"color: #006699; font-weight: bold;\">export<\/span> <span style=\"color: #006699; font-weight: bold;\">namespace<\/span> math {\n\n    <span style=\"color: #007788; font-weight: bold;\">int<\/span> add(<span style=\"color: #007788; font-weight: bold;\">int<\/span> fir, <span style=\"color: #007788; font-weight: bold;\">int<\/span> sec);\n \n    <span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">getProduct<\/span>(<span style=\"color: #006699; font-weight: bold;\">const<\/span> std<span style=\"color: #555555;\">::<\/span>vector<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;&amp;<\/span> vec);\n\n}\n<\/pre>\n<\/div>\n<ul>\n<li>The module interface unit contains the exporting module declaration: <span style=\"font-family: courier new, courier;\">export module math<\/span>.<\/li>\n<li>The names <span style=\"font-family: courier new, courier;\">add<\/span>, and <span style=\"font-family: courier new, courier;\">getProduct<\/span> are exported.<\/li>\n<li>A module can have only one module interface unit.<\/li>\n<\/ul>\n<h3>Module Implementation Unit<\/h3>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ mathImplementationUnit.cpp<\/span>\n\nmodule math;\n\nimport std.core;\n\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">add<\/span>(<span style=\"color: #007788; font-weight: bold;\">int<\/span> fir, <span style=\"color: #007788; font-weight: bold;\">int<\/span> sec){\n    <span style=\"color: #006699; font-weight: bold;\">return<\/span> fir <span style=\"color: #555555;\">+<\/span> sec;\n}\n\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">getProduct<\/span>(<span style=\"color: #006699; font-weight: bold;\">const<\/span> std<span style=\"color: #555555;\">::<\/span>vector<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;&amp;<\/span> vec) {\n    <span style=\"color: #006699; font-weight: bold;\">return<\/span> std<span style=\"color: #555555;\">::<\/span>accumulate(vec.begin(), vec.end(), <span style=\"color: #ff6600;\">1<\/span>, std<span style=\"color: #555555;\">::<\/span>multiplies<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;<\/span>());\n}\n<\/pre>\n<\/div>\n<ul>\n<li>The module implementation unit contains non-exporting module declarations: <span style=\"font-family: courier new, courier;\">module math;<\/span><\/li>\n<li>A module can have more than one module implementation unit.<\/li>\n<\/ul>\n<h3>Main Program<\/h3>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ client3.cpp<\/span>\n\nimport std.core;\n\nimport math;\n\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">main<\/span>() {\n    \n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;   \n   \n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"math::add(2000, 20): \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> math<span style=\"color: #555555;\">::<\/span>add(<span style=\"color: #ff6600;\">2000<\/span>, <span style=\"color: #ff6600;\">20<\/span>) <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\n    \n    std<span style=\"color: #555555;\">::<\/span>vector<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;<\/span> myVec{<span style=\"color: #ff6600;\">1<\/span>, <span style=\"color: #ff6600;\">2<\/span>, <span style=\"color: #ff6600;\">3<\/span>, <span style=\"color: #ff6600;\">4<\/span>, <span style=\"color: #ff6600;\">5<\/span>, <span style=\"color: #ff6600;\">6<\/span>, <span style=\"color: #ff6600;\">7<\/span>, <span style=\"color: #ff6600;\">8<\/span>, <span style=\"color: #ff6600;\">9<\/span>, <span style=\"color: #ff6600;\">10<\/span>};\n    \n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"math::getProduct(myVec): \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> math<span style=\"color: #555555;\">::<\/span>getProduct(myVec) <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\n    \n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\n   \n}\n<\/pre>\n<\/div>\n<ul>\n<li>\u00a0From the user&#8217;s perspective, only the namespace <span style=\"font-family: courier new, courier;\">math was added<\/span>.\u00a0<span style=\"font-family: courier new, courier;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<h3>Building the Executable<\/h3>\n<p>Manually building the executable includes a few steps.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\">cl.exe <span style=\"color: #555555;\">\/<\/span>std<span style=\"color: #555555;\">:<\/span>c<span style=\"color: #555555;\">++<\/span>latest <span style=\"color: #555555;\">\/<\/span>c <span style=\"color: #555555;\">\/<\/span>experimental<span style=\"color: #555555;\">:<\/span>module mathInterfaceUnit.ixx <span style=\"color: #555555;\">\/<\/span>EHsc <span style=\"color: #555555;\">\/<\/span>MD      <span style=\"color: #0099ff; font-style: italic;\">\/\/ (1)<\/span>\ncl.exe <span style=\"color: #555555;\">\/<\/span>std<span style=\"color: #555555;\">:<\/span>c<span style=\"color: #555555;\">++<\/span>latest <span style=\"color: #555555;\">\/<\/span>c <span style=\"color: #555555;\">\/<\/span>experimental<span style=\"color: #555555;\">:<\/span>module mathImplementationUnit.cpp <span style=\"color: #555555;\">\/<\/span>EHsc <span style=\"color: #555555;\">\/<\/span>MD <span style=\"color: #0099ff; font-style: italic;\">\/\/ (2)<\/span>\ncl.exe <span style=\"color: #555555;\">\/<\/span>std<span style=\"color: #555555;\">:<\/span>c<span style=\"color: #555555;\">++<\/span>latest <span style=\"color: #555555;\">\/<\/span>c <span style=\"color: #555555;\">\/<\/span>experimental<span style=\"color: #555555;\">:<\/span>module client3.cpp <span style=\"color: #555555;\">\/<\/span>EHsc <span style=\"color: #555555;\">\/<\/span>MD                <span style=\"color: #0099ff; font-style: italic;\">\/\/ (3)<\/span>\ncl.exe client3.obj mathInterfaceUnit.obj mathImplementationUnit.obj                <span style=\"color: #0099ff; font-style: italic;\">\/\/ (4)<\/span>\n<\/pre>\n<\/div>\n<ol>\n<li>Creates the object file <span style=\"font-family: courier new, courier;\">mathInterfaceUnit.ob<\/span>j and the module interface file <span style=\"font-family: courier new, courier;\">math.ifc.<\/span><\/li>\n<li>Creates the object file<span style=\"font-family: courier new, courier;\"> mathImplementationUnit.obj.<\/span><\/li>\n<li>Creates the object file <span style=\"font-family: courier new, courier;\">client3.obj.<\/span><\/li>\n<li>Creates the executable <span style=\"font-family: courier new, courier;\">client3.exe.<\/span><\/li>\n<\/ol>\n<p>Specify the exception handling model (\/EHsc) and the multithreading library (\/MD) for the Microsoft compiler.\u00a0 Additionally, use the flag\u00a0<a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/build\/reference\/std-specify-language-standard-version?view=vs-2019\"><span style=\"font-family: courier new, courier;\">\/std:c++latest<\/span><\/a>.<\/p>\n<p>Finally, here is the output of the program:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5911\" style=\"display: block; margin-left: auto; margin-right: auto;\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2020\/05\/client3.png\" alt=\"client3\" width=\"350\" height=\"161\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2020\/05\/client3.png 1168w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2020\/05\/client3-300x138.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2020\/05\/client3-1024x470.png 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2020\/05\/client3-768x352.png 768w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><\/p>\n<h2>What&#8217;s next?<\/h2>\n<p>I will extend my module math in the next post with new features. First, I import and export modules in one unit; second, I use names only visible inside the module.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Thanks to the module interface unit and implementation unit, you can separate the interface from the implementation when defining a module. Let me show you how.<\/p>\n","protected":false},"author":21,"featured_media":8397,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[375],"tags":[443],"class_list":["post-5912","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-20","tag-modules"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=5912"}],"version-history":[{"count":2,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5912\/revisions"}],"predecessor-version":[{"id":8401,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5912\/revisions\/8401"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/8397"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=5912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=5912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=5912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}