<div dir="ltr">Hello there,<br><br>I am trying to create a simple Clang plugin and test it on my Windows host with Msys2's mingw x86_64-w64-windows toolchain. The issue is that clang is failing to "find" the plugin after loading 

windows plugin dll. Can you please help me to figure out what is wrong here? I am very new to clang and the plugin framework. Thank you for any suggestion, Mark<br><div><br></div><div>1. creating plugin dll:</div><div><br></div><div>$ make -f <a href="http://makefile.mk/" target="_blank">makefile.mk</a><br>clang++ -c -std=c++14 -fno-exceptions -fno-rtti  -D_FILE_OFFSET_BITS=64 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS   -I. -Ic:/msys64/mingw64/include  example_plugin_clang.cpp -o example_plugin_clang.o<br>clang++ -shared example_plugin_clang.o -static -o <b>example-plugin-clang.dll</b> -Lc:/msys64/mingw64/lib c:/msys64/mingw64/lib/<b>libclang-cpp.dll.a</b> c:/msys64/mingw64/lib/<b>libLLVM.dll.a</b><br></div><div><br></div><div>2. test run: </div><div><br></div><div> $ make -f <a href="http://makefile.mk/" target="_blank">makefile.mk</a> test<br></div>clang++ -Xclang -load -Xclang  <CURDIR> /<b>example-plugin-clang.dll</b> -Xclang -add-plugin -Xclang example-plugin-clang -c -std=c++11 example_cpp_class.cc -o example_cpp_class.o<br>error: unable to find plugin 'example-plugin-clang'<br>1 error generated.<br>mingw32-make: *** [<a href="http://makefile.mk:86/" target="_blank">makefile.mk:86</a>: example_cpp_class.o] Error 1<div><br></div><div>...</div><div>$ nm example-plugin-clang.dll | grep example<br>00000000701c1cb0 t _GLOBAL__sub_I_example_plugin_clang.cpp<br>00000000701e9020 b _ZL26_example_plugin_clang_node<br></div><div><br></div><div>per example_plugin_clang.cpp:</div><div><br></div><div>static FrontendPluginRegistry::Add<FindDependenciesAction><br>_example_plugin_clang_node(/*plugin Name=*/          "example-plugin-clang",<br>                           /*plugin Description=*/   "Print out header dependencies");<br></div><div><br></div><div>$ ntldd example-plugin-clang.dll<br>        libclang-cpp.dll => C:\msys64\mingw64\bin\libclang-cpp.dll (0x0000000000e10000)<br>        KERNEL32.dll => C:\WINDOWS\SYSTEM32\KERNEL32.dll (0x0000000005690000)<br>        msvcrt.dll => C:\WINDOWS\SYSTEM32\msvcrt.dll (0x00000000006d0000)<br></div><div><br></div><div>***</div><div><br></div><div>I tried an example for GCC plugin with the Msys2 GCC toolchain and this works:</div><div><br></div><div>$ make -f <a href="http://makefile.mk">makefile.mk</a><br>g++ -c -std=c++11 -Wno-literal-suffix  -fno-exceptions -fno-rtti   -I. -Ic:/msys64/mingw64/include -Ic:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/9.3.0/plugin/include  example_plugin_gcc.cpp -o example_plugin_gcc.o<br>g++ -shared example_plugin_gcc.o -static -o example-plugin-gcc.dll c:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/9.3.0/plugin/<b>cc1plus.exe.a</b><br><br>$ make -f <a href="http://makefile.mk">makefile.mk</a> test<br>g++  -fplugin=C:/Users/msx/demo/plugin/<b>example-plugin-gcc.dll</b> -c -std=c++11 example_cpp_class.cc -o example_cpp_class.o<br>Plugin info<br>===========<br><br>Base name: example-plugin-gcc<br>Full name: C:/Users/msx/demo/plugin/example-plugin-gcc.dll<br>Number of arguments of this plugin:0<br><br>Version info<br>============<br><br>Base version: 9.3.0<br>Date stamp: 20200312<br>Dev phase:<br>Revision:<br>Configuration arguments: ../gcc-9.3.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++ --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --enable-plugin --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev2, Built by MSYS2 project' --with-bugurl=<a href="https://sourceforge.net/projects/msys2">https://sourceforge.net/projects/msys2</a> --with-gnu-as --with-gnu-ld<br><br>Plugin successfully initialized<br><br></div><div>*** Other relevant info for clang plugin build ***</div><div><br></div><div>$ ldd example-plugin-clang.dll<br>        ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7fff6fb30000)<br>        KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7fff6f890000)<br>        KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll (0x7fff6c610000)<br>        msvcrt.dll => /c/WINDOWS/System32/msvcrt.dll (0x7fff6d540000)<br>        libclang-cpp.dll => /c/msys64/mingw64/bin/libclang-cpp.dll (0x67400000)<br>        ADVAPI32.dll => /c/WINDOWS/System32/ADVAPI32.dll (0x7fff6d020000)<br>        sechost.dll => /c/WINDOWS/System32/sechost.dll (0x7fff6e2c0000)<br>        zlib1.dll => /mingw64/bin/zlib1.dll (0x62e80000)<br>        RPCRT4.dll => /c/WINDOWS/System32/RPCRT4.dll (0x7fff6cec0000)<br>        ole32.dll => /c/WINDOWS/System32/ole32.dll (0x7fff6d300000)<br>        combase.dll => /c/WINDOWS/System32/combase.dll (0x7fff6de50000)<br>        ucrtbase.dll => /c/WINDOWS/System32/ucrtbase.dll (0x7fff6c970000)<br>        bcryptPrimitives.dll => /c/WINDOWS/System32/bcryptPrimitives.dll (0x7fff6c4e0000)<br>        GDI32.dll => /c/WINDOWS/System32/GDI32.dll (0x7fff6e360000)<br>        gdi32full.dll => /c/WINDOWS/System32/gdi32full.dll (0x7fff6bbf0000)<br>        msvcp_win.dll => /c/WINDOWS/System32/msvcp_win.dll (0x7fff6c8d0000)<br>        USER32.dll => /c/WINDOWS/System32/USER32.dll (0x7fff6dcb0000)<br>        win32u.dll => /c/WINDOWS/System32/win32u.dll (0x7fff6ca70000)<br>        SHELL32.dll => /c/WINDOWS/System32/SHELL32.dll (0x7fff6e390000)<br>        cfgmgr32.dll => /c/WINDOWS/System32/cfgmgr32.dll (0x7fff6c560000)<br>        shcore.dll => /c/WINDOWS/System32/shcore.dll (0x7fff6db80000)<br>        libwinpthread-1.dll => /mingw64/bin/libwinpthread-1.dll (0x64940000)<br>        windows.storage.dll => /c/WINDOWS/System32/windows.storage.dll (0x7fff6bd90000)<br>        profapi.dll => /c/WINDOWS/System32/profapi.dll (0x7fff6bb40000)<br>        powrprof.dll => /c/WINDOWS/System32/powrprof.dll (0x7fff6bb70000)<br>        shlwapi.dll => /c/WINDOWS/System32/shlwapi.dll (0x7fff6d2a0000)<br>        kernel.appcore.dll => /c/WINDOWS/System32/kernel.appcore.dll (0x7fff6bbd0000)<br>        cryptsp.dll => /c/WINDOWS/System32/cryptsp.dll (0x7fff6c8b0000)<br>        VERSION.dll => /c/WINDOWS/SYSTEM32/VERSION.dll (0x7fff60a40000)<br>        libstdc++-6.dll => /mingw64/bin/libstdc++-6.dll (0x6fc40000)<br>        libgcc_s_seh-1.dll => /mingw64/bin/libgcc_s_seh-1.dll (0x61440000)<br>        libz3.dll => /c/msys64/mingw64/bin/libz3.dll (0xcf0000)<br>        libz3.dll => /c/msys64/mingw64/bin/libz3.dll (0xcf0000)<br></div><div><br></div><div>- Tools -</div><div><br></div><div>Compiler:<br><br>$ clang++ --version<br>clang version 10.0.0 (<a href="https://github.com/msys2/MINGW-packages.git3f880aaba91a3d9cdfb222dc270274731a2119a9" rel="noreferrer" target="_blank">https://github.com/msys2/MINGW-packages.git<br>3f880aaba91a3d9cdfb222dc270274731a2119a9</a>)<br>Target: x86_64-w64-windows-gnu<br>Thread model: posix<br>InstalledDir: C:\msys64\mingw64\bin<br><br>w/<br><br>$ llvm-config --version<br>10.0.0<br><br>Linker:<br><br>$ /c/msys64/mingw64/bin/ld --version<br>GNU ld (GNU Binutils) 2.34<br>Copyright (C) 2020 Free Software Foundation, Inc.<br>This program is free software; you may redistribute it under the terms of<br>the GNU General Public License version 3 or (at your option) a later<br>version.<br>This program has absolutely no warranty.<br><br>Make:<br><br>$ mingw32-make --version<br>GNU Make 4.3<br>Built for Windows32<br>Copyright (C) 1988-2020 Free Software Foundation, Inc.<br>License GPLv3+: GNU GPL version 3 or later</div></div>