<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
code
{mso-style-priority:99;
font-family:"Courier New";}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0cm;
font-size:10.0pt;
font-family:"Courier New";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:"Courier New";}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:2145653922;
mso-list-type:hybrid;
mso-list-template-ids:1894936414 -1 134807555 134807557 134807553 134807555 134807557 134807553 134807555 134807557;}
@list l0:level1
{mso-level-start-at:0;
mso-level-number-format:bullet;
mso-level-text:-;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-font-family:"Times New Roman";}
@list l0:level2
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level3
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level4
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level5
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level6
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level7
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level8
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level9
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></style></head><body lang=EN-GB link=blue vlink="#954F72" style='word-wrap:break-word'><div class=WordSection1><p class=MsoNormal>I have cloned the llvm-project repository.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Then I have generated a Visual Studio solution for the project using:</p><p class=MsoNormal><o:p> </o:p></p><div><pre style='vertical-align:baseline'><code><span style='font-family:Consolas;border:none windowtext 1.0pt;padding:0cm'>cmake -G "Visual Studio 16" -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON -DLLVM_TARGETS_TO_BUILD=X86 -DCLANG_BUILD_EXAMPLES=ON -DCMAKE_INSTALL_PREFIX=install ...\llvm-project\llvm<o:p></o:p></span></code></pre></div><p class=MsoNormal style='margin-bottom:var(--s-prose-spacing);font-variant-ligatures: normal;font-variant-caps: normal;font-variant-numeric: inherit;font-variant-east-asian: inherit;font-stretch: inherit;line-height:inherit;box-sizing: inherit;orphans: 2;widows: 2;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;word-spacing:0px'><o:p> </o:p></p><p class=MsoNormal>The important part is DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS, as suggested here:</p><p class=MsoNormal><a href="https://llvm.discourse.group/t/how-to-create-pass-independently-on-windows/474/5">https://llvm.discourse.group/t/how-to-create-pass-independently-on-windows/474/5</a></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The solution and all the projects are generated. Then I build Clang itself and an example clang plugin that is already provided in the llvm-project source. The PrintFunctionNames seem to be the hello world of Clang plugins, so I have built that, according to the llvm documentation.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The build successfully ran, and now I have llvm/clang in the install dir, with the PrintFunctionNames plugin.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The problem is that I can not invoke the plugin. As far as I know, there is 3 ways to tell calng to use your plugin.</p><p class=MsoNormal><o:p> </o:p></p><ul style='margin-top:0cm' type=disc><li class=MsoListParagraph style='margin-left:0cm;mso-list:l0 level1 lfo1'>The cc1 interface:</li></ul><p class=MsoListParagraph>I can call my plugin with:</p><p class=MsoListParagraph>clang -cc1 -load PrintFunctionNames.dll -plugin print-fns test.cpp</p><p class=MsoListParagraph>This only works with clang and won’t work with clang++. Moreover, clang won’t find the standard headers, but that is expected behaviour with cc1 according to the documentation.</p><p class=MsoListParagraph><o:p> </o:p></p><ul style='margin-top:0cm' type=disc><li class=MsoListParagraph style='margin-left:0cm;mso-list:l0 level1 lfo1'>The -Xclang interface:</li></ul><pre style='margin-left:36.0pt;vertical-align:baseline'><code><span style='font-family:Consolas;border:none windowtext 1.0pt;padding:0cm'>I call my plugin with:<o:p></o:p></span></code></pre><pre style='margin-left:36.0pt;vertical-align:baseline'><code><span style='font-family:Consolas;border:none windowtext 1.0pt;padding:0cm'>clang -Xclang -load -Xclang PrintFunctionNames.dll -Xclang -plugin -Xclang print-fns test.cpp<o:p></o:p></span></code></pre><pre style='margin-left:36.0pt;vertical-align:baseline'><code><span style='font-family:Consolas;border:none windowtext 1.0pt;padding:0cm'>This works aswell, and since Xclang appends to the cc1, standard library headers are found too. However, calling clang++ instead of clang won’t work here either. Clang++ outputs an error: unable to find plugin 'print-fns'.<o:p></o:p></span></code></pre><pre style='margin-left:36.0pt;vertical-align:baseline'><code><span style='font-family:Consolas;border:none windowtext 1.0pt;padding:0cm'><o:p> </o:p></span></code></pre><pre style='margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1;vertical-align:baseline'><![if !supportLists]><span style='font-family:"Calibri",sans-serif;border:none windowtext 1.0pt;padding:0cm'><span style='mso-list:Ignore'>-<span style='font:7.0pt "Times New Roman"'> </span></span></span><![endif]><span style='font-family:Consolas;border:none windowtext 1.0pt;padding:0cm'>The fplugin interface:<o:p></o:p></span></pre><pre style='margin-left:36.0pt;vertical-align:baseline'><span style='font-family:Consolas;border:none windowtext 1.0pt;padding:0cm'>I have added the necessary code according to the documentation:<o:p></o:p></span></pre><pre style='margin-left:36.0pt;vertical-align:baseline'><span style='font-family:Consolas;border:none windowtext 1.0pt;padding:0cm'><a href="https://clang.llvm.org/docs/ClangPlugins.html">https://clang.llvm.org/docs/ClangPlugins.html</a><o:p></o:p></span></pre><p class=MsoListParagraph>// Automatically run the plugin after the main AST action</p><p class=MsoListParagraph>PluginASTAction::ActionType getActionType() override {</p><p class=MsoListParagraph> return AddAfterMainAction;</p><p class=MsoListParagraph>}</p><p class=MsoListParagraph>After that, I can run the plugin with:</p><p class=MsoListParagraph>clang -fplugin=<code><span style='font-size:10.0pt;font-family:Consolas;border:none windowtext 1.0pt;padding:0cm'>PrintFunctionNames</span></code>.dll test.cpp</p><p class=MsoListParagraph>This runs as expected, but once again, clang++ wont run the plugin. Moreover, no error messages are generated, clang++ just refuses to run the plugin.</p><p class=MsoListParagraph><o:p> </o:p></p><p class=MsoNormal>I do not understand why clang seems to work fine with plugins, but clang++ refuses to run any. I have tried all the provided example plugins, none of them works with clang++, while all of them works as expected with clang.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I have tested both the latest version and llvm 11 too, I am using windows 10.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I would really appreciate any insights as to why clang++ would behave differently when it comes to plugins.</p></div></body></html>