none
Can the toolset v140_clang_3_7 in Visual Studio 2015 load a clang plugin at runtime

    Question

  • Hi,

    I would like to develop a clang plugin to mess around with the AST that clang produce. On osX I managed to do it, but i need to change my pdevelopment platform and this is a feature that is needed for my application.

    At the moment I just try to follow this tutorial.

    http://clang.llvm.org/docs/ClangPlugins.html

    I managed to build my dll using the VisualStudio 2015 v140 toolset. Then when I compile my project I add to the command line of the compiler: -Xclang -load -Xclang $(OUTDIR)PrintFunctionNames.dll -Xclang -plugin -Xclang print-fns .

    So the PrintFunctionNames.dll is compiled with VisualStudio 2015 v140toolset and not v140_clang_3_7 because it can't compile the clang header, or just crash the compiler in debug. ( now that i think of it I got the header from the official git depot, maybe i should try the microsoft fork, but i doubt it will solve. v140_clang_3_7 should be able to load dll)

    ok now the issue, so I have my dll compiled with  VisualStudio 2015 v140 toolset, I added to the compiler command line  -Xclang -load -Xclang $(OUTDIR)PrintFunctionNames.dll -Xclang -plugin -Xclang print-fns and I get this error:

    CLANGCOMPILE : error : unable to load plugin 'C:\.....\PrintFunctionNames.dll': 'C:\....\PrintFunctionNames.dll: Can't open : Unknown error'

    Before I lose too much time on this is this even suppored at the moment?

    Thanks

    Saturday, February 20, 2016 6:59 PM

All replies

  • Hi MonAmiMani,

    According to the error message, please check whether you have referenced the PrintFunctionNames.dll correctly.

    Besides, please provided the detailed steps how do you create the Clang plugin and use it in your project to help us reproduce your problem.

    In addition, the v140_clang_3_7 toolset is a new features in Visual Studio 2015 Update1, please refer to below blog to check whether you are using it correctly.

    https://blogs.msdn.microsoft.com/vcblog/2015/12/04/clang-with-microsoft-codegen-in-vs-2015-update-1/

    Best Regards,
    Weiwei

    Monday, February 22, 2016 8:34 AM
    Moderator
  • As you can see the compiler command line -Xclang -load -Xclang $(OUTDIR)PrintFunctionNames.dll -Xclang -plugin -Xclang print-fn expand to -Xclang -load -Xclang "C:\Users\monamiami\Development\projects\Narcissus\Build\x64\Debug\NarcissusPlugin.dll" -Xclang -plugin -Xclang print-fns  

    With MSBUILD verbosity set to Detailed i get this

    1>         C:\Program Files (x86)\MSBuild\14.0\bin\Tracker.exe /d "C:\Program Files (x86)\MSBuild\14.0\bin\FileTracker.dll" /i C:\Users\monamiami\Development\projects\Narcissus\Tmp\NarcissusUnitTest\x64\Release\Narcissu.CB352AC5.tlog /r C:\USERS\MONAMIAMI\DEVELOPMENT\PROJECTS\NARCISSUS\SOURCE\NARCISSUSUNITTEST\MAIN.CPP /b MSBuildConsole_CancelEventc5c6452124e7489abe06066beac4c8d0  /c "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Clang 3.7\bin\x86\clang.exe"  -c -fdiagnostics-format=msvc -target "amd64-pc-windows-msvc" -I "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Clang 3.7\include" -I "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include" -I "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include" -I "C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\ucrt" -I "C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\um" -I "C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\shared" -I "C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\winrt" -I "C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6\Include\um" -gline-tables-only -o "C:\Users\monamiami\Development\projects\Narcissus\Build\..\Tmp\NarcissusUnitTest\x64\Release\main.obj" -Wall -O2 -fno-strict-aliasing -fomit-frame-pointer -fexceptions -ffunction-sections -fdata-sections -fstack-protector -fpic -fno-short-enums -fno-rtti -D _MBCS -x c++ -fms-extensions -fno-ms-compatibility -Xclang -load -Xclang "C:\Users\monamiami\Development\projects\Narcissus\Build\..\Bin\x64\Release\NarcissusPlugin.dll" -Xclang -plugin -Xclang print-fns  -D_MT -D_DLL -Xclang --dependent-lib=msvcrt -Xclang --dependent-lib=oldnames ..\..\Source\NarcissusUnitTest\main.cpp
    1>     1>
    1>CLANGCOMPILE : error : unable to load plugin 'C:\Users\monamiami\Development\projects\Narcissus\Build\..\Bin\x64\Release\NarcissusPlugin.dll': 'C:\Users\monamiami\Development\projects\Narcissus\Build\..\Bin\x64\Release\NarcissusPlugin.dll: Can't open : Unknown error'
    1>         The command exited with code 1.
    1>       Done executing task "ClangCompile" -- FAILED.

    The dll is present C:\Users\monamiami\Development\projects\Narcissus\Build\..\Bin\x64\Debug\

    If you could forward this to someone that worked on the clang integration in visual studio I would be grateful as this is an "advance" feature of clang.
    • Edited by MonAmiMani Thursday, March 03, 2016 2:29 AM
    Thursday, March 03, 2016 2:27 AM
  • Hi MonAmiMani,

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Thanks for your understanding!

    Best Regards,
    Weiwei

    Friday, March 04, 2016 1:14 AM
    Moderator