Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vtk] link error when linking agains vtk:x64-windows-static #9947

Closed
dbonhaus opened this issue Feb 6, 2020 · 40 comments · Fixed by #20356
Closed

[vtk] link error when linking agains vtk:x64-windows-static #9947

dbonhaus opened this issue Feb 6, 2020 · 40 comments · Fixed by #20356
Assignees
Labels
category:port-bug The issue is with a library, which is something the port should already support

Comments

@dbonhaus
Copy link

dbonhaus commented Feb 6, 2020

On Windows 10 using CMake 3.16.0 with Visual Studio 17, I get the following link error when building against vtk:x64-windows-static:
LINK : fatal error LNK1104: cannot open file 'pugixml.lib'
A sample CMakeLists file is attached. The source file contains an empty main method.

CMakeLists.txt

@JackBoosY JackBoosY added the category:port-bug The issue is with a library, which is something the port should already support label Feb 7, 2020
@JackBoosY
Copy link
Contributor

Confirmed.

@JackBoosY
Copy link
Contributor

After changing LINK_PRIVATE to LINK_PUBLIC in SOURCE/IO/CityGML/CMakeLists.txt line 7, it works.

@JackBoosY
Copy link
Contributor

Hi @dbonhaus, thanks for reporting this issue!
I've fixed it in #9958, please update vcpkg and rebuild vtk.

Thanks.

@dbonhaus
Copy link
Author

Somehow I am still getting the same error. I updated my local copy of vcpkg, made sure that the relevant change was there, then reinstalled VTK (vtk:x64-windows-static) from scratch. I then deleted the cache for my sample project and reconfigured and rebuilt it, but I'm still getting the pugixml link error.

@JackBoosY
Copy link
Contributor

@dbonhaus Could you provide failure log?

@dbonhaus
Copy link
Author

The error message is not very informative:
"LINK : fatal error LNK1104: cannot open file 'pugixml.lib'"

The problem seems to be that pugixml.lib is in the project properties, but without an absolute path. I uploaded a snapshot of the linker properties in Visual Studio. Let me know if there is another log file that might be more informative and I will provide it.

vtktest_libs

@JackBoosY
Copy link
Contributor

@dbonhaus
Did you create this project yourself? vcpkg will add VCPKG_PATH/installed/TRIPLET/lib / VCPKG_PATH/installed/TRIPLET/debug/lib to the path LIB_PATH and try to link all static libraries in this path, so pugixml.lib should not be added by vcpkg.

@dbonhaus
Copy link
Author

No, the project was generated by CMake (3.16.0).

@JackBoosY
Copy link
Contributor

JackBoosY commented Feb 14, 2020

Confimed.
In VTKTargets.cmake:

set_target_properties(vtkIOCityGML PROPERTIES
  INTERFACE_COMPILE_FEATURES "cxx_nullptr;cxx_override"
  INTERFACE_LINK_LIBRARIES "vtkCommonCore;vtkCommonExecutionModel;vtkFiltersGeneral;vtkFiltersModeling;\$<LINK_ONLY:vtkCommonDataModel>;\$<LINK_ONLY:vtksys>;pugixml"
)

@JackBoosY JackBoosY reopened this Feb 14, 2020
@manvscode
Copy link
Contributor

manvscode commented Mar 9, 2020

@JackBoosY I am having the same issue after updating vcpkg packages (one of which was vtk).

@JackBoosY
Copy link
Contributor

In IO\CityGML\CMakeLists.txt:

if(VTK_USE_SYSTEM_PUGIXML AND NOT pugixml_INCLUDE_DIRS)
  find_package(pugixml REQUIRED)
  vtk_module_link_libraries(vtkIOCityGML LINK_PUBLIC pugixml)
endif()

I think this is caused by the incorrect use of pugixml.

@JackBoosY
Copy link
Contributor

@dbonhaus @manvscode
Could you add find_dependency(pugixml CONFIG) to VCPKG_PATH/installed/TRIPLET/share/VTK/VTKConfig.cmake line 110?

If it works, I will open a PR to fix it.

@RamanKutseika
Copy link

Hello @JackBoosY.
I having the same issue @manvscode described.
Adding find_dependency(pugixml CONFIG) doesn't seem to work.
изображение

@JackBoosY
Copy link
Contributor

@RamadanAhmed Sorry, we should include CMakeFindDependencyMacro.cmake first:

include(CMakeFindDependencyMacro)
find_dependency(pugixml CONFIG)

@RamanKutseika
Copy link

RamanKutseika commented Mar 10, 2020

@JackBoosY after applying suggested changes I see the same issue with the pugixml.lib unfortunately.
The thing which is a bit confusing to me is that debug build should actually use the pugixml**_d**.lib but it is looking for pugixml.lib instead. Maybe this can give you a hint.

@jasjuang
Copy link
Contributor

Just ran into the same problem.

What solved it temporarily for me is adding these two lines at the end of the installed VTKConfig.cmake

include(CMakeFindDependencyMacro)
find_dependency(pugixml REQUIRED)

Look forward to the proper fix.

@dbonhaus
Copy link
Author

dbonhaus commented Mar 10, 2020

@dbonhaus @manvscode
Could you add find_dependency(pugixml CONFIG) to VCPKG_PATH/installed/TRIPLET/share/VTK/VTKConfig.cmake line 110?

If it works, I will open a PR to fix it.

I no longer see link errors involving pugixml, but I see two new ones:

1>vtkIOCore-8.2.lib(vtkLZMADataCompressor.cxx.obj) : error LNK2019: unresolved external symbol __imp_lzma_easy_buffer_encode referenced in function "protected: virtual unsigned __int64 __cdecl vtkLZMADataCompressor::CompressBuffer(unsigned char const *,unsigned __int64,unsigned char *,unsigned __int64)" (?CompressBuffer@vtkLZMADataCompressor@@MEAA_KPEBE_KPEAE1@Z)
1>vtkIOCore-8.2.lib(vtkLZMADataCompressor.cxx.obj) : error LNK2019: unresolved external symbol __imp_lzma_stream_buffer_decode referenced in function "protected: virtual unsigned __int64 __cdecl vtkLZMADataCompressor::UncompressBuffer(unsigned char const *,unsigned __int64,unsigned char *,unsigned __int64)" (?UncompressBuffer@vtkLZMADataCompressor@@MEAA_KPEBE_KPEAE1@Z)

I have the 2020.01 tag of vcpkg checked out.

@manvscode
Copy link
Contributor

manvscode commented Mar 10, 2020

@JackBoosY @RamanKutseika @dbonhaus I can confirm that adding these lines to VTKConfig.cmake, at line 110, will fix the problem:

include(CMakeFindDependencyMacro)
find_dependency(pugixml REQUIRED)

I tested both linking debug and release binaries. I do not see any problems with liblzma.

@JackBoosY
Copy link
Contributor

JackBoosY commented Mar 11, 2020

@RamanKutseika Port pugixml generated debug library named pugixml.lib, so I guess no fault here.

@JackBoosY
Copy link
Contributor

@dbonhaus
lzma library should be imported with path ${VTK_INSTALL_PREFIX}/lib/lzma.lib and ${VTK_INSTALL_PREFIX}/debug/lib/lzmad.lib, you can find them in share\vtk\Modules\vtklzma.cmake

And VTK_INSTALL_PREFIX was set in VTKConfig,cmake line 13:

if (_vtk_installed_prefix_full STREQUAL _vtk_requested_prefix_full)
  set(VTK_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/../..")
else ()
  set(VTK_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}")
  get_filename_component(VTK_INSTALL_PREFIX "${VTK_INSTALL_PREFIX}" PATH)
  get_filename_component(VTK_INSTALL_PREFIX "${VTK_INSTALL_PREFIX}" PATH)
endif ()

@JackBoosY
Copy link
Contributor

Hi guys, I've fixed this issue in #10379, please update vcpkg and rebuild vtk.

Thanks.

@dbonhaus
Copy link
Author

@dbonhaus
lzma library should be imported with path ${VTK_INSTALL_PREFIX}/lib/lzma.lib and ${VTK_INSTALL_PREFIX}/debug/lib/lzmad.lib, you can find them in share\vtk\Modules\vtklzma.cmake

And VTK_INSTALL_PREFIX was set in VTKConfig,cmake line 13:

if (_vtk_installed_prefix_full STREQUAL _vtk_requested_prefix_full)
  set(VTK_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/../..")
else ()
  set(VTK_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}")
  get_filename_component(VTK_INSTALL_PREFIX "${VTK_INSTALL_PREFIX}" PATH)
  get_filename_component(VTK_INSTALL_PREFIX "${VTK_INSTALL_PREFIX}" PATH)
endif ()

I just tried the latest vcpkg and I'm still seeing problems with lzma (but not with pugixml). I'm not sure I follow your comment. Are you saying I should explicitly specify lzma as a dependency in my CMake file? Shouldn't VTK take care of the dependency? Everything seems to be as you indicated in the VTK config files.

@JackBoosY JackBoosY reopened this Apr 2, 2020
@JackBoosY
Copy link
Contributor

JackBoosY commented Apr 3, 2020

@dbonhaus
According to my comment above, lzma was imported through VTK_INSTALL_PREFIX to determine the absolute path of the dependent library, and the value of VTK_INSTALL_PREFIX is VCPKG_PATH/installed/TRIPLET/share/vtk/../.., then lzma library path should be VCPKG_PATH/installed/TRIPLET/share/vtk/../../lib/lzma.lib and VCPKG_PATH/installed/TRIPLET/share/vtk/../../debug/lib/lzmad.lib. So we don't need to find lzma through find_package / find_dependency again.
So I think there should be no problem here.

Could you provide the failure log?

@dbonhaus
Copy link
Author

dbonhaus commented Apr 4, 2020

Here are the link errors:

1>vtkIOCore-8.2.lib(vtkLZMADataCompressor.cxx.obj) : error LNK2019: unresolved external symbol __imp_lzma_easy_buffer_encode referenced in function "protected: virtual unsigned __int64 __cdecl vtkLZMADataCompressor::CompressBuffer(unsigned char const *,unsigned __int64,unsigned char *,unsigned __int64)" (?CompressBuffer@vtkLZMADataCompressor@@MEAA_KPEBE_KPEAE1@Z)
1>vtkIOCore-8.2.lib(vtkLZMADataCompressor.cxx.obj) : error LNK2019: unresolved external symbol __imp_lzma_stream_buffer_decode referenced in function "protected: virtual unsigned __int64 __cdecl vtkLZMADataCompressor::UncompressBuffer(unsigned char const *,unsigned __int64,unsigned char *,unsigned __int64)" (?UncompressBuffer@vtkLZMADataCompressor@@MEAA_KPEBE_KPEAE1@Z)

@JackBoosY
Copy link
Contributor

@dbonhaus Could you provide the full log?

Thanks.

@dbonhaus
Copy link
Author

dbonhaus commented Apr 7, 2020

I modified the test project to reproduce the error.
vtk_test.zip

I also included the CMake cache file. I suspect something about the CMake configuration either is the problem or triggers the problem.

@dbonhaus
Copy link
Author

dbonhaus commented Apr 7, 2020

There seem to be a lot more problems with the test project associated with the use of the static run time (x64-windows-static). I added /MT to the CXX flags but it didn't help.

@JackBoosY
Copy link
Contributor

Well, now I can confirm that this issue still exists and I will continue to deal with this issue.

@JackBoosY
Copy link
Contributor

__imp_lzma_easy_buffer_encode incorrect EXPORT macro, I will fix this issue in the nearly futhre.

@JackBoosY
Copy link
Contributor

@Neumann-A Seems the export cmake files has problem, what do you think?

@Neumann-A
Copy link
Contributor

@JackBoosY: Is ParaView not built in x64-windows-static CI? I would have thought that this would have found such an issue in VTK (or LZMA).

@Neumann-A
Copy link
Contributor

@JackBoosY I checked the logs of #12342 and Paraview built fine with it. Maybe the problem is linking against VTK_LIBRARIES instead of a target? I currently don't have a installation of VTK so I cannot check the value of VTK_LIBRARIES.

@JackBoosY
Copy link
Contributor

@Neumann-A ParaView is not added to the pre-build process currently, and this issue appeared before adding ParaView.

@dbonhaus Does this issue still exist? Please note to use find_package(vtk CONFIG REQUIRED) instead of find_package(VTK CONFIG REQUIRED).

@GeneralAdmin
Copy link

I've the same issue with vcpkg using wide integration.

@JackBoosY
Copy link
Contributor

@GeneralAdmin More details please?

@dbonhaus
Copy link
Author

I no longer see any link errors as of vcpkg 2020.11 if I use find_package(VTK CONFIG REQUIRED). It doesn't work with lower case vtk. If I specify components in the find_package command, I see the link error again, but that seems like a VTK issue rather than a vcpkg issue.

@JackBoosY
Copy link
Contributor

@dbonhaus thanks for the information.

@JackBoosY
Copy link
Contributor

JackBoosY commented Nov 13, 2020

Hi @martinken, can you please take a look?
We are not sure this issue is caused by vtk itself or vcpkg.

In the share folder:

 Directory of F:\vcpkg\installed\x64-windows-static\share\vtk

11/13/2020  12:15 AM    <DIR>          .
11/13/2020  12:15 AM    <DIR>          ..
06/24/2020  08:25 AM             1,761 copyright
11/13/2020  12:02 AM             1,063 Finddouble-conversion.cmake
11/13/2020  12:02 AM             1,396 FindEigen3.cmake
11/13/2020  12:02 AM             4,029 FindEXPAT.cmake
11/13/2020  12:02 AM             6,470 FindFFMPEG.cmake
11/13/2020  12:02 AM             1,739 FindFontConfig.cmake
11/13/2020  12:02 AM             7,447 FindFreetype.cmake
11/13/2020  12:02 AM             1,490 FindGL2PS.cmake
11/13/2020  12:02 AM               905 FindGLEW.cmake
11/13/2020  12:02 AM             1,905 FindJOGL.cmake
11/13/2020  12:02 AM             1,874 FindJsonCpp.cmake
11/13/2020  12:02 AM             3,697 FindLibHaru.cmake
11/13/2020  12:02 AM             2,901 FindLibPROJ.cmake
11/13/2020  12:02 AM             4,104 FindLibXml2.cmake
11/13/2020  12:02 AM               136 FindLZ4.cmake
11/13/2020  12:02 AM             3,208 FindLZMA.cmake
11/13/2020  12:02 AM             1,226 Findmpi4py.cmake
11/13/2020  12:02 AM             3,815 FindMySQL.cmake
11/13/2020  12:02 AM             3,654 FindNetCDF.cmake
11/13/2020  12:02 AM             2,162 FindODBC.cmake
11/13/2020  12:02 AM               688 FindOGG.cmake
11/13/2020  12:02 AM            23,053 FindOpenMP.cmake
11/13/2020  12:02 AM             1,298 FindOpenSlide.cmake
11/13/2020  12:02 AM             1,659 FindOpenVR.cmake
11/13/2020  12:02 AM             2,223 FindOSMesa.cmake
11/13/2020  12:02 AM             2,125 FindPEGTL.cmake
11/13/2020  12:02 AM            15,952 FindTBB.cmake
11/13/2020  12:02 AM             2,078 FindTHEORA.cmake
11/13/2020  12:02 AM               578 Findutf8cpp.cmake
11/13/2020  12:15 AM    <DIR>          patches
11/12/2020  10:53 PM             2,916 vcpkg_abi_info.txt
11/13/2020  12:02 AM             1,419 vtk-config-version.cmake
11/13/2020  12:02 AM            14,448 vtk-config.cmake
11/13/2020  12:02 AM               244 vtk-prefix.cmake
11/13/2020  12:02 AM            58,291 VTK-targets-debug.cmake
11/13/2020  12:02 AM            57,693 VTK-targets-release.cmake
11/13/2020  12:02 AM            59,557 VTK-targets.cmake
11/13/2020  12:02 AM                18 vtk-use-file-compat.cmake
11/13/2020  12:02 AM                84 vtk-use-file-deprecated.cmake
11/13/2020  12:02 AM               181 vtk-use-file-error.cmake
11/13/2020  12:02 AM            53,008 VTK-vtk-module-find-packages.cmake
11/13/2020  12:02 AM           298,605 VTK-vtk-module-properties.cmake
11/13/2020  12:02 AM               525 vtkCMakeBackports.cmake
11/13/2020  12:02 AM             4,687 vtkDetectLibraryType.cmake
11/13/2020  12:02 AM             7,469 vtkEncodeString.cmake
11/13/2020  12:02 AM             3,218 vtkHashSource.cmake
11/13/2020  12:02 AM           191,813 vtkModule.cmake
11/13/2020  12:02 AM            13,259 vtkModuleGraphviz.cmake
11/13/2020  12:02 AM             7,093 vtkModuleJson.cmake
11/13/2020  12:02 AM            21,956 vtkModuleTesting.cmake
11/13/2020  12:02 AM            14,383 vtkModuleWrapJava.cmake
11/13/2020  12:02 AM            44,651 vtkModuleWrapPython.cmake
11/13/2020  12:02 AM             6,669 vtkObjectFactory.cmake
06/24/2020  08:25 AM             1,958 vtkObjectFactory.cxx.in
06/24/2020  08:25 AM             1,680 vtkObjectFactory.h.in
11/13/2020  12:02 AM               289 vtkTestingDriver.cmake
11/13/2020  12:02 AM             2,880 vtkTestingRenderingDriver.cmake
11/13/2020  12:02 AM             5,621 vtkTopologicalSort.cmake
              57 File(s)        979,251 bytes
               3 Dir(s)  814,283,091,968 bytes free

I found that some cmake files start with uppercase VTK, and the rest start with lowercase vtk. I think there is something wrong here.

@Neumann-A
Copy link
Contributor

I found that some cmake files start with uppercase VTK, and the rest start with lowercase vtk. I think there is something wrong here.

no it is not.....

vtk-config.cmake is the important one

due to its naming the config can be found via find_package(VTK) AND find_packakge(vtk) but this doesn't mean both are correct. Internally VTKs config is probably using PACKAGE_FIND_NAME somewhere which is why lowercase vtk is not working. That said the correct way to find VTK is to always use uppercase VTK since that is used in any example by vtk itself (https://gitlab.kitware.com/vtk/vtk/-/blob/master/Examples/GUI/Qt/ImageViewer/CMakeLists.txt).

So this issue can be closed since find_package(VTK) is working

@JackBoosY
Copy link
Contributor

JackBoosY commented Nov 16, 2020

@Neumann-A At least our usage is incorrect:

The package vtk:x64-windows-static provides CMake targets:

    find_package(3.13 CONFIG REQUIRED)
    target_link_libraries(main PRIVATE ZLIB::ZLIB)

    find_package(3.16 CONFIG REQUIRED)
    target_link_libraries(main PRIVATE PostgreSQL::PostgreSQL)

    find_package(99 CONFIG REQUIRED)
    # Note: 36 target(s) were omitted.
    target_link_libraries(main PRIVATE X11::SM X11::Xi X11::Xt X11::Xv)

    find_package(vtk CONFIG REQUIRED)
    # Note: 159 target(s) were omitted.
    target_link_libraries(main PRIVATE LZ4::LZ4 OGG::OGG VTK::lz4 VTK::ogg)

PS F:\vcpkg>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:port-bug The issue is with a library, which is something the port should already support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants