Fixes a build issue noted in D111100. Backport requested to 14.x once this lands.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
This patch is having problems on Windows with MSVC 2019 and -D LLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON and -D "LLVM_ENABLE_PROJECTS=clang;clang-tools-extra".
CMake doesn't configure the project.
-- Clang version: 14.0.0 -- SampleAnalyzerPlugin ignored -- Loadable modules not supported on this platform. CMake Error at C:/Projects/llvm-project/repo/clang/cmake/modules/AddClang.cmake:185 (target_link_libraries): Utility target "SampleAnalyzerPlugin" must not be used as the target of a target_link_libraries call. Call Stack (most recent call first): C:/Projects/llvm-project/repo/clang/lib/Analysis/plugins/SampleAnalyzer/CMakeLists.txt:8 (clang_target_link_libraries) -- CheckerDependencyHandlingAnalyzerPlugin ignored -- Loadable modules not supported on this platform. CMake Error at C:/Projects/llvm-project/repo/clang/cmake/modules/AddClang.cmake:185 (target_link_libraries): Utility target "CheckerDependencyHandlingAnalyzerPlugin" must not be used as the target of a target_link_libraries call. Call Stack (most recent call first): C:/Projects/llvm-project/repo/clang/lib/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt:8 (clang_target_link_libraries) -- CheckerOptionHandlingAnalyzerPlugin ignored -- Loadable modules not supported on this platform. CMake Error at C:/Projects/llvm-project/repo/clang/cmake/modules/AddClang.cmake:185 (target_link_libraries): Utility target "CheckerOptionHandlingAnalyzerPlugin" must not be used as the target of a target_link_libraries call. Call Stack (most recent call first): C:/Projects/llvm-project/repo/clang/lib/Analysis/plugins/CheckerOptionHandling/CMakeLists.txt:8 (clang_target_link_libraries)
@cristian.adam Is this good now? You are blocking merging this, but I think it is ready to land, and I would like to not hold it up for other people if it is fixing their issues (and the issues you discovered too)
I did a rebase on release/14.x, applied this commit and, got the same error:
-- SampleAnalyzerPlugin ignored -- Loadable modules not supported on this platform. CMake Error at C:/Projects/llvm-project/repo/clang/cmake/modules/AddClang.cmake:185 (target_link_libraries): Utility target "SampleAnalyzerPlugin" must not be used as the target of a target_link_libraries call. Call Stack (most recent call first): C:/Projects/llvm-project/repo/clang/lib/Analysis/plugins/SampleAnalyzer/CMakeLists.txt:8 (clang_target_link_libraries) -- CheckerDependencyHandlingAnalyzerPlugin ignored -- Loadable modules not supported on this platform. CMake Error at C:/Projects/llvm-project/repo/clang/cmake/modules/AddClang.cmake:185 (target_link_libraries): Utility target "CheckerDependencyHandlingAnalyzerPlugin" must not be used as the target of a target_link_libraries call. Call Stack (most recent call first): C:/Projects/llvm-project/repo/clang/lib/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt:8 (clang_target_link_libraries) -- CheckerOptionHandlingAnalyzerPlugin ignored -- Loadable modules not supported on this platform. CMake Error at C:/Projects/llvm-project/repo/clang/cmake/modules/AddClang.cmake:185 (target_link_libraries): Utility target "CheckerOptionHandlingAnalyzerPlugin" must not be used as the target of a target_link_libraries call. Call Stack (most recent call first): C:/Projects/llvm-project/repo/clang/lib/Analysis/plugins/CheckerOptionHandling/CMakeLists.txt:8 (clang_target_link_libraries)
I'll be away for a week, so I won't be blocking anybody now. I'll have to deal with building LLVM/Clang 14 when I come back.
Thanks, if you encounter more issues next week, let me know, and I will continue trying to adjust it to work for all config option combinations.
Hi. This commit seems to have broken the following cmake command, on Windows (with HEAD pointing at 76cad51ba700233d6e3492eddcbb466b6adbc2eb):
cmake -DLLVM_ENABLE_PROJECTS=clang -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON ..\llvm-project\llvm
The symptom is the same as @cristian.adam shows above:
-- SampleAnalyzerPlugin ignored -- Loadable modules not supported on this platform. CMake Error at [...]/llvm-project/clang/cmake/modules/AddClang.cmake:185 (target_link_libraries): Utility target "SampleAnalyzerPlugin" must not be used as the target of a target_link_libraries call. Call Stack (most recent call first): [...]/llvm-project/clang/lib/Analysis/plugins/SampleAnalyzer/CMakeLists.txt:8 (clang_target_link_libraries)
With HEAD pointing at the previous commit, clang/lib/Analysis/plugins/CMakeLists.txt does not add the SampleAnalyzer subdirectory at all, because LLVM_ENABLE_PLUGINS has the value OFF. But CLANG_PLUGIN_SUPPORT is ON, so now it does, and the above error happens.
If I try to work around this by setting CLANG_PLUGIN_SUPPORT to OFF as well ...
cmake -DLLVM_ENABLE_PROJECTS=clang -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON -DCLANG_PLUGIN_SUPPORT=OFF ..\llvm-project\llvm
... then this error happens instead:
CMake Error at cmake/modules/AddLLVM.cmake:676 (target_link_libraries): Target "clang" of type EXECUTABLE may not be linked into another target. One may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to executables with the ENABLE_EXPORTS property set. Call Stack (most recent call first): cmake/modules/AddLLVM.cmake:808 (llvm_add_library) [...]/llvm-project/clang/examples/PrintFunctionNames/CMakeLists.txt:12 (add_llvm_library)
So, either way, the build fails.
clang/tools/driver/CMakeLists.txt | ||
---|---|---|
53 | I think we've managed to fix our build by changing this line so that it tests if(CLANG_PLUGIN_SUPPORT OR LLVM_EXPORT_SYMBOLS_FOR_PLUGINS) because that fixes the cmake complaint that you can't link against an executable that didn't have ENABLE_EXPORTS. |
release/14.x now configures but fails to build on MSVC2019 with -D LLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON like at https://reviews.llvm.org/D111100
FAILED: bin/CTTestTidyModule.dll cmd.exe /C "cd . && C:\tools\cmake\bin\cmake.exe -E vs_link_dll --intdir=tools\clang\tools\extra\test\CMakeFiles\CTTestTidyModule.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\mt.exe --manifests -- C:\PROGRA~2\MICROS~1\2019\BUILDT~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe /nologo tools\clang\tools\extra\test\CMakeFiles\CTTestTidyModule.dir\clang-tidy\CTTestTidyModule.cpp.obj /out:bin\CTTestTidyModule.dll /implib:lib\CTTestTidyModule.lib /pdb:bin\CTTestTidyModule.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO lib\clang-tidy.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ." LINK: command "C:\PROGRA~2\MICROS~1\2019\BUILDT~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe /nologo tools\clang\tools\extra\test\CMakeFiles\CTTestTidyModule.dir\clang-tidy\CTTestTidyModule.cpp.obj /out:bin\CTTestTidyModule.dll /implib:lib\CTTestTidyModule.lib /pdb:bin\CTTestTidyModule.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO lib\clang-tidy.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:bin\CTTestTidyModule.dll.manifest" failed (exit code 1120) with the following output: CTTestTidyModule.cpp.obj : error LNK2001: unresolved external symbol "class clang::ast_matchers::internal::VariadicDynCastAllOfMatcher<class clang::Decl,class clang::TranslationUnitDecl> const clang::ast_matchers::translationUnitDecl" (?translationUnitDecl@ast_matchers@clang@@3V?$VariadicDynCastAllOfMatcher@VDecl@clang@@VTranslationUnitDecl@2@@internal@12@B) bin\CTTestTidyModule.dll : fatal error LNK1120: 1 unresolved externals
Is that a bug in clang or in MSVC2019? We expected that CLANG_PLUGIN_SUPPORT=ON can expose problems with the Windows linker, and we add new tests here for verifying that configuration is functioning as expected. You might need to disable CLANG_PLUGIN_SUPPORT on that target?
I don't know. I "fixed" it by commenting out the whole creation of the target, the same way as the LLVM_INSTALL_TOOLCHAIN_ONLY does, which would be the other workaround, to just use LLVM_INSTALL_TOOLCHAIN_ONLY.
diff --git a/clang-tools-extra/test/CMakeLists.txt b/clang-tools-extra/test/CMakeLists.txt index 170e5f8bd197..e8b897893776 100644 --- a/clang-tools-extra/test/CMakeLists.txt +++ b/clang-tools-extra/test/CMakeLists.txt @@ -80,6 +80,7 @@ foreach(dep ${LLVM_UTILS_DEPS}) endif() endforeach() +#[[ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) llvm_add_library( CTTestTidyModule @@ -106,6 +107,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) endif() endif() endif() +#]]
I think we've managed to fix our build by changing this line so that it tests
because that fixes the cmake complaint that you can't link against an executable that didn't have ENABLE_EXPORTS.