{"id":109823,"date":"2024-05-30T07:00:00","date_gmt":"2024-05-30T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=109823"},"modified":"2024-06-02T07:45:39","modified_gmt":"2024-06-02T14:45:39","slug":"20240530-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20240530-00\/?p=109823","title":{"rendered":"A graphical depiction of the steps in building a C++ executable, enhanced for classic Win32"},"content":{"rendered":"<p>Last time, we generated a diagram showing <a title=\"A graphical depiction of the steps in building a C++ executable, basics\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20240529-00\/?p=109818\"> the basics of how a C++ executable is built<\/a>. The diagram applies to Windows programs too, but it is often the case that some of the parts that go into the C++ build are themselves build outputs of other tools. And there are usually other parts of a Windows program that aren&#8217;t covered by the C++ build workflow because they produce things beyond just a C++ program.<\/p>\n<p>Let&#8217;s add some of them into our diagram, at least the ones most often seen in classic Win32 apps.<\/p>\n<p>&nbsp;<\/p>\n<div id=\"p20240530_head\" style=\"display: none;\">\u00a0<\/div>\n<div id=\"p20240530_defs\" style=\"height: 0;\">\u00a0<\/div>\n<table style=\"text-align: center; border-collapse: separate; line-height: 1;\" title=\"Described in text.\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td style=\"border: solid 1px currentcolor; padding: 1ex;\">.idl<\/td>\n<td>&nbsp;<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td id=\"p20240530_darr\">\u2193<\/td>\n<td>&nbsp;<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td style=\"border: solid 1px currentcolor; border-radius: 3ex; padding: 1ex;\">MIDL compiler<\/td>\n<td>&nbsp;<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td id=\"p20240530_darr\">\u2193<\/td>\n<td>&nbsp;<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td style=\"border: solid 1px currentcolor; position: relative;\" colspan=\"3\">\n<div style=\"position: absolute; top: 0; left: 0; background: currentcolor; opacity: 15%; width: 100%; height: 100%;\">\u00a0<\/div>\n<div style=\"width: 100%; height: 100%; padding: 1ex;\">.h, .cpp<\/div>\n<\/td>\n<td>&nbsp;<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td style=\"background: currentcolor; opacity: 15%;\">\u00a0<\/td>\n<td style=\"background: currentcolor; opacity: 15%;\">\u00a0<\/td>\n<td style=\"position: relative;\">\n<div style=\"position: absolute; top: 0; left: 0; background: currentcolor; opacity: 15%; width: 100%; height: 100%;\">\u00a0<\/div>\n<div id=\"p20240530_darr\">\u2193<\/div>\n<\/td>\n<td>&nbsp;<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td style=\"background: currentcolor; opacity: 15%;\">\u00a0<\/td>\n<td style=\"background: currentcolor; opacity: 15%;\">\u00a0<\/td>\n<td style=\"position: relative; padding: 0; line-height: 2em;\">\n<div style=\"position: absolute; top: 0; left: 0; background: currentcolor; opacity: 15%; width: 100%; height: 100%;\">\u00a0<\/div>\n<div style=\"border: solid 1px currentcolor; border-radius: 3ex; height: 100%; line-height: 1; padding: 1ex;\">C++ compiler<\/div>\n<\/td>\n<td>&nbsp;<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td style=\"background: currentcolor; opacity: 15%;\">\u00a0<\/td>\n<td style=\"background: currentcolor; opacity: 15%;\">\u00a0<\/td>\n<td style=\"position: relative;\">\n<div style=\"position: absolute; top: 0; left: 0; background: currentcolor; opacity: 15%; width: 100%; height: 100%;\">\u00a0<\/div>\n<div id=\"p20240530_darr\">\u2193<\/div>\n<\/td>\n<td>&nbsp;<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td style=\"background: currentcolor; opacity: 15%;\">\u00a0<\/td>\n<td style=\"background: currentcolor; opacity: 15%;\">\u00a0<\/td>\n<td style=\"border: solid 1px currentcolor; padding: 1ex; position: relative;\">\n<div style=\"position: absolute; top: 0; left: 0; background: currentcolor; opacity: 15%; width: 100%; height: 100%;\">\u00a0<\/div>\n<div style=\"width: 100%; height: 100%;\">.obj<\/div>\n<\/td>\n<td>&nbsp;<\/td>\n<td style=\"border: solid 1px currentcolor; padding: 1ex;\">.rc, .ico, .bmp<\/td>\n<\/tr>\n<tr>\n<td style=\"background: currentcolor; opacity: 15%;\">\u00a0<\/td>\n<td style=\"position: relative;\">\n<div style=\"position: absolute; top: 0; left: 0; background: currentcolor; opacity: 15%; width: 100%; height: 100%;\">\u00a0<\/div>\n<div id=\"p20240530_swarr\">\u2199<\/div>\n<\/td>\n<td style=\"position: relative;\" rowspan=\"5\">\n<div style=\"position: absolute; top: 0; left: 0; background: currentcolor; opacity: 15%; width: 100%; height: 100%;\">\u00a0<\/div>\n<div id=\"p20240530_darr5\">\u2193<br \/>\n\u2193<br \/>\n\u2193<br \/>\n\u2193<br \/>\n\u2193<br \/>\n\u2193<br \/>\n\u2193<\/div>\n<\/td>\n<td>&nbsp;<\/td>\n<td id=\"p20240530_darr\">\u2193<\/td>\n<\/tr>\n<tr>\n<td style=\"position: relative; padding: 0; line-height: 2em;\">\n<div style=\"position: absolute; top: 0; left: 0; background: currentcolor; opacity: 15%; width: 100%; height: 100%;\">\u00a0<\/div>\n<div style=\"border: solid 1px currentcolor; border-radius: 3ex; height: 100%;\">librarian<\/div>\n<\/td>\n<td style=\"background: currentcolor; opacity: 15%;\"><!-- missing td: rowspan 2 of 5 --><\/td>\n<td>&nbsp;<\/td>\n<td style=\"border: solid 1px currentcolor; border-radius: 3ex; padding: 1ex;\">rc compiler<\/td>\n<\/tr>\n<tr>\n<td style=\"position: relative;\">\n<div style=\"position: absolute; top: 0; left: 0; background: currentcolor; opacity: 15%; width: 100%; height: 100%;\">\u00a0<\/div>\n<div id=\"p20240530_darr\">\u2193<\/div>\n<\/td>\n<td style=\"background: currentcolor; opacity: 15%;\"><!-- missing td: rowspan 3 of 5 --><\/td>\n<td>&nbsp;<\/td>\n<td id=\"p20240530_darr\">\u2193<\/td>\n<\/tr>\n<tr>\n<td style=\"border: solid 1px currentcolor; padding: 1ex; position: relative;\">\n<div style=\"position: absolute; top: 0; left: 0; background: currentcolor; opacity: 15%; width: 100%; height: 100%;\">\u00a0<\/div>\n<div style=\"width: 100%; height: 100%;\">.lib<\/div>\n<\/td>\n<td style=\"background: currentcolor; opacity: 15%;\"><!-- missing td: rowspan 4 of 5 --><\/td>\n<td>&nbsp;<\/td>\n<td style=\"border: solid 1px currentcolor; padding: 1ex;\">.res<\/td>\n<\/tr>\n<tr>\n<td style=\"background: currentcolor; opacity: 15%;\">\u00a0<\/td>\n<td style=\"position: relative;\">\n<div style=\"position: absolute; top: 0; left: 0; background: currentcolor; opacity: 15%; width: 100%; height: 100%;\">\u00a0<\/div>\n<div id=\"p20240530_searr\">\u2198<\/div>\n<p><!-- missing td: rowspan 5 of 5 --><\/td>\n<td id=\"p20240530_swarr\">\u2199<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td style=\"background: currentcolor; opacity: 15%;\">\u00a0<\/td>\n<td style=\"background: currentcolor; opacity: 15%;\">\u00a0<\/td>\n<td style=\"position: relative; padding: 0; line-height: 2em;\">\n<div style=\"position: absolute; top: 0; left: 0; background: currentcolor; opacity: 15%; width: 100%; height: 100%;\">\u00a0<\/div>\n<div style=\"border: solid 1px currentcolor; border-radius: 3ex; height: 100%;\">linker<\/div>\n<\/td>\n<td>&nbsp;<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td style=\"background: currentcolor; opacity: 15%;\">\u00a0<\/td>\n<td style=\"background: currentcolor; opacity: 15%;\">\u00a0<\/td>\n<td style=\"position: relative;\">\n<div style=\"position: absolute; top: 0; left: 0; background: currentcolor; opacity: 15%; width: 100%; height: 100%;\">\u00a0<\/div>\n<div id=\"p20240530_darr\">\u2193<\/div>\n<\/td>\n<td>&nbsp;<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td style=\"background: currentcolor; opacity: 15%;\">\u00a0<\/td>\n<td style=\"background: currentcolor; opacity: 15%;\">\u00a0<\/td>\n<td style=\"border: solid 1px currentcolor; padding: 1ex; position: relative;\">\n<div style=\"position: absolute; top: 0; left: 0; background: currentcolor; opacity: 15%; width: 100%; height: 100%;\">\u00a0<\/div>\n<div style=\"width: 100%; height: 100%;\">.dll, .exe<\/div>\n<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The original diagram is still there in the bottom left corner, where it consumes C++ source files (.h, .cpp) and eventually produces a module (.dll, .exe). The added steps are things that either produce C++ source files from other sources or add additional content to the resulting module.<\/p>\n<p>If there is an .idl file, it is processed by the MIDL compiler, which produces .h and .c files, which you consume in your project code.<\/p>\n<p>You may have other code generators as part of your project. If you have a yacc grammar or a Lottie animation, you&#8217;ll also have a compiler compiler or an animation generator as a code generation step, to take the raw materials and turn them into code and resources that are consumed as inputs by other boxes.<\/p>\n<p>Once we have generated all the C++ source files, we can go through the process we saw last time: Compile the C++ source files to object files, and possibly generate a .lib.<\/p>\n<p>Meanwhile, for classic Win32 resources, the resource compiler takes the .rc file and any supporting files (like .ico and .bmp) and produces a .res file.<\/p>\n<p>After all the .obj, .lib, and .res files have been produced, we feed them all to the linker, which produces the resulting module, a .dll or .exe.<\/p>\n<p>The essence of the process hasn&#8217;t changed. There&#8217;s just more rigmarole before the compilation (to produce header files and code), alongside the compilation (to produce a resource file), and after the compilation (to incorporate the resources into the final binary).<\/p>\n<p>Next time, we&#8217;ll add more rigamarole around the central diagram by adding packaging and XAML.<\/p>\n<p>\n<script>\nwindow.addEventListener(\"load\", function() {\n  var fullFF = getComputedStyle(document.body).fontFamily;\n  var simpleFF = fullFF.replace(\/ Emoji\/g, \"\");\n  \/\/ break up \"style\" to prevent wordpress from injecting random junk\n  document.getElementById(\"p20240530_head\").innerHTML =\n`<s` + `tyle>\nbody { font-family: ${simpleFF}; }\n.emoji { font-family: ${fullFF}; }\n.entry-content th { padding: 1px; } \/* stylesheet workaround *\/\n.entry-content td { padding: 1px; } \/* stylesheet workaround *\/\n<\/s` + `tyle>`;\n}); \/\/ wacky comment to prevent wordpress from injecting random junk\n(function() {\n  var svg = {\n    defs: `<svg width=\"0\" height=\"0\">\n <defs>\n  <marker id=\"arrowhead\" markerWidth=\"5\" markerHeight=\"5\" refX=\"-2\" refY=\"0\"\n    viewBox=\"-6 -6 12 12\" orient=\"auto\">\n    <polygon points=\"-2,0 -5,5 5,0 -5,-5\" fill=\"currentcolor\" stroke=\"currentcolor\"\n      stroke-dasharray=\"1 0\" \/>\n  <\/marker>\n  <path id=\"darr\" d=\"M10,3 L10,15\" stroke=\"currentcolor\"\n   marker-end=\"url(#arrowhead)\" \/>\n  <path id=\"darr5\" d=\"M10,3 L10,125\" stroke=\"currentcolor\"\n   marker-end=\"url(#arrowhead)\" \/>\n  <path id=\"searr\" d=\"M3,3 L15,15\" stroke=\"currentcolor\"\n   marker-end=\"url(#arrowhead)\" \/>\n  <path id=\"swarr\" d=\"M20,2 L3,15\" stroke=\"currentcolor\"\n   marker-end=\"url(#arrowhead)\" \/>\n <\/defs>\n<\/svg>`,\n    darr: `<svg width=\"20\" height=\"20\"><use href=\"#darr\"\/><\/svg>`,\n    darr5: `<svg width=\"20\" height=\"130\"><use href=\"#darr5\"\/><\/svg>`,\n    searr: `<svg width=\"20\" height=\"20\"><use href=\"#searr\"\/><\/svg>`,\n    swarr: `<svg width=\"20\" height=\"20\"><use href=\"#swarr\"\/><\/svg>`\n  };\n  Object.keys(svg).forEach(function (key) {\n    Array.prototype.forEach.call(document.querySelectorAll(\"#p20240530_\" + key),\n      function (e) {\n        e.innerHTML = svg[key];\n      });\n  });\n})();\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Adding in Microsoft-specific tools.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-109823","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Adding in Microsoft-specific tools.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/109823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=109823"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/109823\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=109823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=109823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=109823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}