VTK failed to build due to error LNK2019 and error LNK1120 on Windows with msvc

VTK failed to build due to error LNK2019 and error LNK1120 on Windows with msvc, could anyone help look at this issue? Thanks.

Repro steps:

  1. git clone https://gitlab.kitware.com/vtk/vtk F:\gitP\vtk\vtk
  2. git -C “F:\gitP\vtk\vtk” reset --hard d731e5ec
  3. git -C “F:\gitP\vtk\vtk” submodule sync
  4. git -C “F:\gitP\vtk\vtk” submodule update --init --recursive
  5. set VSCMD_SKIP_SENDTELEMETRY=1 & “C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat” -host_arch=amd64 -arch=amd64
  6. mkdir F:\gitP\vtk\vtk\build_amd64 and cd F:\gitP\vtk\vtk\build_amd64
  8. msbuild /m /p:Platform=x64 /p:Configuration=Release All_BUILD.vcxproj /t:Rebuild

Actural result:

"F:\gitP\vtk\vtk\build_amd64\All_BUILD.vcxproj" (Rebuild target) (1) ->
"F:\gitP\vtk\vtk\build_amd64\Interaction\Widgets\Testing\Cxx\vtkInteractionWidgetsCxxTests.vcxproj" (default target) (360:2) ->
vtkCommonCore-9.2.lib(vtkSMPToolsAPI.obj) : error LNK2019: unresolved external symbol "public: bool __cdecl vtk::detail::smp::vtkSMPToolsImpl<1>::IsParallelScope(void)" (?IsParallelScope@?$vtkSMPToolsImpl@$00@smp@detail@vtk@@QEAA_NXZ) referenced in function "public: bool __cdecl vtk::detail::smp::vtkSMPToolsAPI::IsParallelScope(void)" (?IsParallelScope@vtkSMPToolsAPI@smp@detail@vtk@@QEAA_NXZ) [F:\gitP\vtk\vtk\build_amd64\Interaction\Widgets\Testing\Cxx\vtkInteractionWidgetsCxxTests.vcxproj]
F:\gitP\vtk\vtk\build_amd64\bin\Release\vtkInteractionWidgetsCxxTests.exe : fatal error LNK1120: 1 unresolved externals [F:\gitP\vtk\vtk\build_amd64\Interaction\Widgets\Testing\Cxx\vtkInteractionWidgetsCxxTests.vcxproj]

build successfully.

More info: OS: Windows server 2022 21H2 Visual Studio: VS2022 17.5.5

-DSMP_IMPLEMENTATION_TYPE=Sequential should fix the issue.


I 'm in the same situation than @Zhaojun-Liu (compiling as static library on windows) and I’m stuck with the same error.

I tried to compile with -DVTK_SMP_IMPLEMENTATION_TYPE=Sequential or “…=Serial” (as seen here : https://gitlab.kitware.com/vtk/vtk/-/issues/18998). Both leaded to the same error.

I also tried all available options for VTK_SMP_IMPLEMENTATION_TYPE when configuring through the cmake gui : same error.

Any idea ?

@alexy.pellegrini @Charles_Gueunet

A colleague told me “it works on my machine”, so we investigated.
The difference was that I was compiling from sources obtained through ‘git clone’ whereas he used the sources obtain from the download pages of the VTK website.

I was able to compile without errors using these sources.

Are you sure you are using the same version ?

If you git clone, you are most likely using master.

The source from the download pages are version 9.2.6, I suppose it correspond to the tag 9.2.6 from master branch which dates from 3 month ago (https://gitlab.kitware.com/vtk/vtk/-/tags/v9.2.6).

And ‘git clone’ gives the last commit from master, which currently dates from today.

I don’t get why this executable is looking for the IsParallelScope method, not any of the underlying tests are using it. The links fails because VTK::FiltersSMP is not in the TEST_DEPENDS list in the Interaction/Widgets/vtk.module file and so the executable can’t find the IsParallelScope method, I will try too understand why it is looking for it in the first place.

Just to be clear, adding the line:


in the TEST_DEPENDS section of the mentionned files is a hotfix that should solve your issue

I tried to add VTK::FiltersSMP to the end of section of TEST_DEPENDS of file Interaction/Widgets/vtk.module like below image, the error still can be reproduced. Do I must add -DSMP_IMPLEMENTATION_TYPE=Sequential to the cmake command?

My mistake, the important line is not VTK::FiltersSMP but VTK::CommonCore, wich is already here.
I reallydo not get why the IsParallelScope methods is involved and why it is not found.
I will continue to think about this error.

If DBUILD_SHARED_LIBS=ON, this problem does not seem to occur. However, in general, DBUILD_SHARED_LIBS=OFF tends to be used more often on Windows because it is more convenient.

Hello, I also tried to build statically on windows. And I’ve got the same error.

Trying to understand why this is happening, I found the generated file: vtkSMP.h
full path: /Common/Core/vtkSMP.h

and the contents of the file have strange definitions:

When I changed VTK_SMP_ENABLE_STDTHREAD equal to 0
all projects were successfully built

CMakeCache.txt contains two options enabled, when it is configured by cmake by default:

You may find more information concerning SMP Tools CMake variable in [our blog].

  • VTK_ENABLE_* control which backend is enabled. At least one should be set
  • VTK_SMP_DEFAULT_IMPLEMENTATION_* control which backend to use by default, one and only one will be set to 1

The reported error is a compilation error that seems to arise when compiling STD Thread backend in a static build. It is not clear for me if the error requires at least two backend to be enabled or if STD Thread only build are also impacted.

I also encountered this problem when compiling a static library. I tried the above methods, but they didn’t seem to work. There is no problem when compiling dynamic libraries. The same cmake configuration only turns off BUILD_SHARED_LIBS. How can I successfully compile the static library?

In Visual Studio 2022, for CommonCore module only, adding /std:c++20 to the compile options successfully generates static libraries with DBUILD_SHARED_LIBS=OFF and either DSMP_IMPLEMENTATION_TYPE=Sequential or DSMP_IMPLEMENTATION_TYPE=STDThread in both cases. On the other hand, adding /std:c++14(default) or /std:c++17 failed in all cases.

Is there a corresponding VTK issue for this issue so that interested parties can track when this defect is fixed?

Thank you.

The issue for this problem can be found at the following link

1 Like