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

**URL:** https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671
**Category:** Development
**Tags:** code
**Created:** [June 12, 2023, 1:33am UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671 "2023-06-12T01:33:15Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![Zhaojun-Liu](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhaojun-liu/32/7243_2.png) [@Zhaojun-Liu](https://discourse.vtk.org/u/Zhaojun-Liu)
#### Post date: [June 12, 2023, 1:33am UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/1 "2023-06-12T01:33:15Z")

</div>

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](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
7. cmake -G “Visual Studio 17 2022” -A x64 -DCMAKE\_SYSTEM\_VERSION=10.0.22621.0 -DBUILD\_SHARED\_LIBS=OFF -DVTK\_BUILD\_TESTING=WANT -DVTK\_BUILD\_EXAMPLES=OFF -DVTK\_IGNORE\_CMAKE\_CXX11\_CHECKS=TRUE -DVTK\_DATA\_EXCLUDE\_FROM\_ALL=ON …
8. msbuild /m /p:Platform=x64 /p:Configuration=Release All\_BUILD.vcxproj /t:Rebuild

Actural result:

```auto
"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]

```

Expected:  
build successfully.

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

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [June 12, 2023, 7:22am UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/2 "2023-06-12T07:22:16Z")

</div>

`-DSMP_IMPLEMENTATION_TYPE=Sequential` should fix the issue.

---

<div class="post-metadata">

### Author: ![segretar](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/cdc98d/32.png) [@segretar](https://discourse.vtk.org/u/segretar)
#### Post date: [June 12, 2023, 2:33pm UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/3 "2023-06-12T14:33:07Z")

</div>

Hi,

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](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 ?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [June 12, 2023, 3:04pm UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/4 "2023-06-12T15:04:31Z")

</div>

@alexy.pellegrini @Charles_Gueunet

---

<div class="post-metadata">

### Author: ![segretar](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/cdc98d/32.png) [@segretar](https://discourse.vtk.org/u/segretar)
#### Post date: [June 12, 2023, 3:43pm UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/5 "2023-06-12T15:43:24Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [June 12, 2023, 3:48pm UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/6 "2023-06-12T15:48:17Z")

</div>

Are you sure you are using the same version ?

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

---

<div class="post-metadata">

### Author: ![segretar](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/cdc98d/32.png) [@segretar](https://discourse.vtk.org/u/segretar)
#### Post date: [June 12, 2023, 4:19pm UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/7 "2023-06-12T16:19:14Z")

</div>

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](https://gitlab.kitware.com/vtk/vtk/-/tags/v9.2.6)).

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

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)
#### Post date: [June 14, 2023, 7:27am UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/8 "2023-06-14T07:27:00Z")

</div>

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:

VTK::FiltersSMP

in the **TEST\_DEPENDS** section of the mentionned files is a hotfix that should solve your issue

---

<div class="post-metadata">

### Author: ![Zhaojun-Liu](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhaojun-liu/32/7243_2.png) [@Zhaojun-Liu](https://discourse.vtk.org/u/Zhaojun-Liu)
#### Post date: [June 14, 2023, 9:40am UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/9 "2023-06-14T09:40:10Z")

</div>

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?

 ![image](https://discourse.vtk.org/uploads/default/original/2X/5/5be4db0e905a0aebb2cd3e5c60fd1ebe8da63bd9.png)

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)
#### Post date: [June 14, 2023, 9:58am UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/10 "2023-06-14T09:58:33Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.vtk.org/u/Kenichiro-Yoshimi)
#### Post date: [August 17, 2023, 4:23am UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/11 "2023-08-17T04:23:50Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dmhud](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dmhud/32/7685_2.png) [@dmhud](https://discourse.vtk.org/u/dmhud)
#### Post date: [September 5, 2023, 10:16pm UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/12 "2023-09-05T22:16:21Z")

</div>

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:  
#define VTK\_SMP\_ENABLE\_OPENMP 0  
#define VTK\_SMP\_ENABLE\_SEQUENTIAL 1  
#define VTK\_SMP\_ENABLE\_STDTHREAD 1  
#define VTK\_SMP\_ENABLE\_TBB 0

When I changed VTK\_SMP\_ENABLE\_STDTHREAD equal to 0  
all projects were successfully built  
#define VTK\_SMP\_ENABLE\_OPENMP 0  
#define VTK\_SMP\_ENABLE\_SEQUENTIAL 1  
#define VTK\_SMP\_ENABLE\_STDTHREAD 0  
#define VTK\_SMP\_ENABLE\_TBB 0

CMakeCache.txt contains two options enabled, when it is configured by cmake by default:  
VTK\_SMP\_ENABLE\_SEQUENTIAL:BOOL=ON  
VTK\_SMP\_ENABLE\_STDTHREAD:BOOL=ON   
VTK\_SMP\_IMPLEMENTATION\_TYPE:STRING=Sequential

 ![2023-09-06_00-54-07](https://discourse.vtk.org/uploads/default/original/2X/f/f0edf825b7fe82c618a245b68fb0d0f8d5ee5f76.png)  
 ![2023-09-06_00-54-49](https://discourse.vtk.org/uploads/default/original/2X/8/816723c736257cf0d7028fa3a843d51178739a8f.png)

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)
#### Post date: [September 6, 2023, 9:41am UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/13 "2023-09-06T09:41:58Z")

</div>

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

- `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.

---

<div class="post-metadata">

### Author: ![zhangyuqiang1995](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhangyuqiang1995/32/7937_2.png) [@zhangyuqiang1995](https://discourse.vtk.org/u/zhangyuqiang1995)
#### Post date: [November 2, 2023, 1:33am UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/14 "2023-11-02T01:33:22Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.vtk.org/u/Kenichiro-Yoshimi)
#### Post date: [November 2, 2023, 9:35am UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/15 "2023-11-02T09:35:16Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![JRocha](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/j/da6949/32.png) [@JRocha](https://discourse.vtk.org/u/JRocha)
#### Post date: [November 17, 2023, 11:59pm UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/16 "2023-11-17T23:59:31Z")

</div>

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

Thank you.

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.vtk.org/u/Kenichiro-Yoshimi)
#### Post date: [November 18, 2023, 1:26am UTC](https://discourse.vtk.org/t/vtk-failed-to-build-due-to-error-lnk2019-and-error-lnk1120-on-windows-with-msvc/11671/17 "2023-11-18T01:26:54Z")

</div>

The issue for this problem can be found at the following link  
[https://gitlab.kitware.com/vtk/vtk/-/issues/19067](https://gitlab.kitware.com/vtk/vtk/-/issues/19067)
