Build failed with VTK: add_library cannot create target "TKernel" because an imported target with the same name already exists

Here is my system information:

❯ neofetch
                   -`                    tim@TimTu-Arch 
                  .o+`                   -------------- 
                 `ooo/                   OS: Arch Linux x86_64 
                `+oooo:                  Host: Code01 Ver2.0 1 
               `+oooooo:                 Kernel: 6.7.2-arch1-2 
               -+oooooo+:                Uptime: 1 day, 7 hours 
             `/:-:++oooo+:               Packages: 1354 (pacman) 
            `/++++/+++++++:              Shell: bash 5.2.26 
           `/++++++++++++++:             Resolution: 2560x1600 
          `/+++ooooooooooooo/`           DE: Plasma 5.27.10 
         ./ooosssso++osssssso+`          WM: kwin 
        .oossssso-````/ossssss+`         Theme: NephriteLight [Plasma], Breeze [GTK2/3] 
       -osssssso.      :ssssssso.        Icons: [Plasma], Colloid [GTK2/3] 
      :osssssss/        osssso+++.       Terminal: konsole 
     /ossssssss/        +ssssooo/-       Terminal Font: Hack [SRC] 10 
   `/ossssso+/:-        -:/+osssso+-     CPU: AMD Ryzen 7 6800H with Radeon Graphics (16) @ 4.785GHz 
  `+sso+:-`                 `.-/+oso:    GPU: AMD ATI Radeon 680M 
 `++:.                           `-/+/   Memory: 21642MiB / 30808MiB 
 .`                                 `/

And here is full log:

❯ sudo cmake .. -DUSE_VTK=ON -D3RDPARTY_VTK_INCLUDE_DIR=/usr/include/vtk
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- The C compiler identification is GNU 13.2.1
-- The CXX compiler identification is GNU 13.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Info. Detecting doxygen
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) (Required is at least version "1.8.4")
-- Info: TCL is used by OCCT
-- Found Tclsh: /bin/tclsh (found version "8.6") 
-- Info: TCL version isn't found
-- Info: TK is used by OCCT
-- Info: TK version isn't found
-- Info: Xlib is used by OCCT
-- Info: FreeType is used by OCCT
-- Found Freetype: /usr/lib/libfreetype.so (found version "2.13.2") 
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Found MPI_C: /usr/lib/libmpi.so (found version "3.1") 
-- Found MPI_CXX: /usr/lib/libmpi_cxx.so (found version "3.1") 
-- Found MPI: TRUE (found version "3.1")  
-- Found PkgConfig: /usr/bin/pkg-config (found version "2.1.0") 
VTK version (9.3.0)
-- Info: The directories of 3rdparty headers: 
        /usr/include
        /usr/include/freetype2
        /usr/include/vtk
-- Info: The directories of 3rdparty libraries: 
        /usr/lib
-- 
Info: (19:26:58) Start collecting all OCCT header files into /tmp/下载/OCCT-7_8_0/build/inc ...
-- Info: (19:26:58) Compare FILES with files in package directories...
-- Info: (19:27:00) Create header-links in inc folder...
-- Info: (19:27:01) Checking headers in inc folder...
-- Info: (19:27:01) End the collecting
CMake Error at adm/cmake/occt_toolkit.cmake:267 (add_library):
  add_library cannot create target "TKernel" because an imported target with
  the same name already exists.
Call Stack (most recent call first):
  CMakeLists.txt:34 (include)
  src/TKernel/CMakeLists.txt:3 (OCCT_INCLUDE_CMAKE_FILE)


CMake Error at adm/cmake/occt_toolkit.cmake:303 (install):
  install TARGETS given target "TKernel" which does not exist.
Call Stack (most recent call first):
  CMakeLists.txt:34 (include)
  src/TKernel/CMakeLists.txt:3 (OCCT_INCLUDE_CMAKE_FILE)


CMake Error at adm/cmake/occt_toolkit.cmake:482 (target_link_libraries):
  Cannot specify link libraries for target "TKernel" which is not built by
  this project.
Call Stack (most recent call first):
  CMakeLists.txt:34 (include)
  src/TKernel/CMakeLists.txt:3 (OCCT_INCLUDE_CMAKE_FILE)
Tim Tu's picture

I'm trying to build OCCT 7.8.0 with VTK. But I met this peoblem. There is no problem if I disable `USE_VTK`. Please help me.

I can't edit this post, because I met: `You have reached this page because you submitted a form that required JavaScript to be enabled on your browser. `

gkv311 n's picture

Just a guess, VTK 9.3 introduced vtkOCCTReader dependency from OCCT. So technically these frameworks may have cyclic dependency when built with specific options like USE_VTK. Which configuration is used for your VTK? Does it already depend from OCCT?