{"id":5583,"date":"2013-01-11T07:00:00","date_gmt":"2013-01-11T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/01\/11\/understanding-errors-in-classical-linking-the-delay-load-catch-22\/"},"modified":"2013-01-11T07:00:00","modified_gmt":"2013-01-11T07:00:00","slug":"understanding-errors-in-classical-linking-the-delay-load-catch-22","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130111-00\/?p=5583","title":{"rendered":"Understanding errors in classical linking: The delay-load catch-22"},"content":{"rendered":"<p><P>\nWrapping up our week of\n<A HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2013\/01\/07\/10382714.aspx\">\nunderstanding the classical model for linking<\/A>,\nwe&#8217;ll put together all the little pieces we&#8217;ve learned this week\nto puzzle out a linker problem:\nThe delay-load catch-22.\n<\/P>\n<P>\nYou do some code cleanup,\nthen rebuild your project, and you get\n<\/P>\n<PRE>\n<A HREF=\"http:\/\/msdn.microsoft.com\/en-us\/library\/a5x38f99.aspx\">LNK4199<\/A>: \/DELAYLOAD:SHLWAPI ignored; no imports found from SHLWAPI\n<\/PRE>\n<P>\nWhat does this error mean?\n<\/P>\n<P>\nIt means that you passed a DLL via the\n<A HREF=\"http:\/\/msdn.microsoft.com\/en-us\/library\/yx9zd12s.aspx\">\n<CODE>\/DELAYLOAD<\/CODE> command line switch<\/A>\nwhich your program doesn&#8217;t actually use,\nso the linker is saying,\n&#8220;Um, you said to treat this DLL special, but I don&#8217;t see that DLL.&#8221;\n<\/P>\n<P>\n&#8220;Oh, right,&#8221; you say to yourself.\n&#8220;I got rid of a call to\n<CODE>Hash&shy;String<\/CODE>,\nand that was probably the last remaining function\nwith a dependency on\n<CODE>SHLWAPI.DLL<\/CODE>.\nThe linker is complaining that I asked to delay-load a DLL\nthat I wasn&#8217;t even loading!&#8221;\n<\/P>\n<P>\nYou fix the problem by deleting\n<CODE>SHLWAPI.DLL<\/CODE> from the <CODE>\/DELAYLOAD<\/CODE>\nlist,\nand removing\n<CODE>SHLWAPI.LIB<\/CODE> from the list of import libararies.\nAnd then you rebuild, and now you get\n<\/P>\n<PRE>\n<A HREF=\"http:\/\/msdn.microsoft.com\/en-us\/library\/799kze2z.aspx\">LNK2019<\/A>: unresolved external &#8216;__imp__HashData&#8217; referenced in function &#8216;HashString&#8217;\n<\/PRE>\n<P>\n&#8220;Wait a second, I stopped calling that function.\nWhat&#8217;s going on!&#8221;\n<\/P>\n<P>\nWhat&#8217;s going on is that the\n<CODE>Hash&shy;String<\/CODE> function got\n<A HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2013\/01\/08\/10383017.aspx\">\ntaken along for the ride<\/A>\nby another function.\nThe order of operations in the linker is\n<\/P>\n<UL>\n<LI>Perform classical linking\n<LI>Perform nonclassical post-processing\n    <UL>\n    <LI>Remove unused functions (if requested)\n    <LI>Apply <CODE>DELAYLOAD<\/CODE> (if requested)\n    <\/UL>\n<\/UL>\n<P>\nThe linker doesn&#8217;t have a crystal ball and say,\n&#8220;I see that in the future, the &#8216;remove unused functions&#8217; step\nis going to delete this function, so I can throw it away right now\nduring the classical linking phase.&#8221;\n<\/P>\n<P>\nYou have a few solutions available to you.\n<\/P>\n<P>\nIf you can modify the library, you can\n<A HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2013\/01\/10\/10383642.aspx\">\nsplit the <CODE>Hash&shy;String<\/CODE>\nfunction out<\/A>\nso that it doesn&#8217;t come along for the ride.\n<\/P>\n<P>\nIf you cannot modify the library,\nthen you&#8217;ll have to\nuse the <CODE>\/IGNORE<\/CODE> flag to explicitly ignore the warning.\n<\/P>\n<P>\n<B>Exercise<\/B>:\nAnother option is to leave <CODE>SHLWAPI.LIB<\/CODE>\nin the list of import libraries,\nbut remove it from the <CODE>DELAYLOAD<\/CODE> list.\nWhy is this a dangerous option?\nWhat can you do to make it less dangerous?\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wrapping up our week of understanding the classical model for linking, we&#8217;ll put together all the little pieces we&#8217;ve learned this week to puzzle out a linker problem: The delay-load catch-22. You do some code cleanup, then rebuild your project, and you get LNK4199: \/DELAYLOAD:SHLWAPI ignored; no imports found from SHLWAPI What does this error [&hellip;]<\/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,131],"class_list":["post-5583","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code","tag-linker"],"acf":[],"blog_post_summary":"<p>Wrapping up our week of understanding the classical model for linking, we&#8217;ll put together all the little pieces we&#8217;ve learned this week to puzzle out a linker problem: The delay-load catch-22. You do some code cleanup, then rebuild your project, and you get LNK4199: \/DELAYLOAD:SHLWAPI ignored; no imports found from SHLWAPI What does this error [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/5583","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=5583"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/5583\/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=5583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=5583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=5583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}