colmap / glomap

GLOMAP - Global Structured-from-Motion Revisited
BSD 3-Clause "New" or "Revised" License
1.3k stars 77 forks source link

Issues with CMake and VS2019: Unresolved External Symbols Related to `cholmod` Functions #42

Closed alLiucb closed 1 month ago

alLiucb commented 1 month ago

Description:

Hello,

I encountered some issues when trying to compile the project using CMake and Visual Studio 2019. Below are the steps, the errors I received, and a modification I made to the CholmodSupport file.

Steps to Reproduce:

  1. Execute the following CMake command:

    PS E:\srcCode\glomap\build> cmake .. -G "Visual Studio 16 2019" -A x64 -DCMAKE_TOOLCHAIN_FILE=E:\myVcpkg\vcpkg\scripts\buildsystems\vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows -D CMAKE_CUDA_ARCHITECTURES="70;75;80;86"
  2. Output from the CMake configuration:

    -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
    -- Configuring PoseLib...
    -- BUILD_SHARED_LIBS: OFF
    -- CMAKE_CONFIGURATION_TYPES: Release;Debug;MinSizeRel;RelWithDebInfo
    -- CMAKE_GENERATOR: Multi-config
    -- CMAKE_GENERATOR: Visual Studio 16 2019
    -- CMAKE_REGISTRY_FOLDER: OFF
    -- Configuring PoseLib... done
    -- Configuring COLMAP...
    -- Enabling LSD support
    CMake Warning at E:/Data_cmake3260/share/cmake-3.26/Modules/FindBoost.cmake:1384 (message):
     New Boost version may have incorrect or missing dependencies and imported
     targets
    Call Stack (most recent call first):
     E:/Data_cmake3260/share/cmake-3.26/Modules/FindBoost.cmake:1508 (_Boost_COMPONENT_DEPENDENCIES)
     E:/Data_cmake3260/share/cmake-3.26/Modules/FindBoost.cmake:2119 (_Boost_MISSING_DEPENDENCIES)
     E:/myVcpkg/vcpkg/installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:11 (_find_package)
     E:/myVcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake:813 (include)
     build/_deps/colmap-src/cmake/FindDependencies.cmake:7 (find_package)
     build/_deps/colmap-src/CMakeLists.txt:105 (include)
    
    (Note: Similar warnings repeated multiple times)
    
    -- Found Boost: E:/myVcpkg/vcpkg/installed/x64-windows/include (found version "1.84.0") found components: filesystem graph program_options system
    -- Found FreeImage
    --   Target : freeimage::FreeImage
    -- Found FLANN
    --   Includes : E:/myVcpkg/vcpkg/installed/x64-windows/include
    --   Libraries : E:/myVcpkg/vcpkg/installed/x64-windows/lib/flann.lib
    -- Found LZ4
    --   Includes : E:/myVcpkg/vcpkg/installed/x64-windows/include
    --   Libraries : E:/myVcpkg/vcpkg/installed/x64-windows/lib/lz4.lib
    -- Found Metis
    --   Target : metis
    -- Found Glog
    --   Target : glog::glog
    -- Looking for sgemm_
    -- Looking for sgemm_ - not found
    -- Looking for sgemm_
    -- Looking for sgemm_ - found
    -- Found BLAS: E:/myVcpkg/vcpkg/installed/x64-windows/debug/lib/openblas.lib
    -- Using VCPKG FindLAPACK from package 'lapack-reference'
    -- Looking for cheev_
    -- Looking for cheev_ - not found
    -- Looking for cheev_
    -- Looking for cheev_ - not found
    -- Looking for cheev_
    -- Looking for cheev_ - found
    -- A library with LAPACK API found.
    -- Found required Ceres dependency: Eigen version 3.4.0 in E:/myVcpkg/vcpkg/installed/x64-windows/share/eigen3
    -- Found Ceres version: 2.1.0 installed in: E:/myVcpkg/vcpkg/installed with components: [LAPACK, SuiteSparse, SparseLinearAlgebraLibrary, SchurSpecializations, Multithreading]
    -- Enabling OpenMP support
    -- Visual Leak Detector (VLD) is not found.
    -- Using header-only CGAL
    -- Targeting Visual Studio 16 2019
    -- Target build environment supports auto-linking
    -- Using VC toolset 142.
    -- Generator uses intermediate configuration directory: $(Configuration)
    -- Found Boost: E:/myVcpkg/vcpkg/installed/x64-windows/include (found suitable version "1.84.0", minimum required is "1.66")
    -- Boost include dirs: E:/myVcpkg/vcpkg/installed/x64-windows/include
    -- Boost libraries:
    -- Found CGAL
    --   Includes : E:/myVcpkg/vcpkg/installed/x64-windows/include
    --   Libraries : CGAL
    -- Enabling CUDA support (version: 11.6.55, archs: 70;75;80;86)
    -- Found Qt
    --   Module : D:/Data_anaconda/Library/lib/cmake/Qt5Core
    --   Module : D:/Data_anaconda/Library/lib/cmake/Qt5OpenGL
    --   Module : D:/Data_anaconda/Library/lib/cmake/Qt5Widgets
    -- Enabling GUI support
    -- Enabling OpenGL support
    -- Enabling GPU support (OpenGL: ON, CUDA: ON)
    -- Build type not specified, using Release
    -- Enabling SIMD support
    -- Enabling interprocedural optimization
    -- Disabling ccache support
    -- Disabling profiling support
    -- Configuring COLMAP... done
    -- Using VCPKG FindLAPACK from package 'lapack-reference'
    -- A library with LAPACK API found.
    -- Found required Ceres dependency: Eigen version 3.4.0 in E:/myVcpkg/vcpkg/installed/x64-windows/share/eigen3
    -- Found Ceres version: 2.1.0 installed in: E:/myVcpkg/vcpkg/installed with components: [LAPACK, SuiteSparse, SparseLinearAlgebraLibrary, SchurSpecializations, Multithreading]
    -- Found Boost: E:/myVcpkg/vcpkg/installed/x64-windows/include (found version "1.84.0")
    -- Enabling OpenMP
    -- Found OpenMP_C: -openmp (found version "2.0")
    -- Found OpenMP_CXX: -openmp (found version "2.0")
    -- Found OpenMP: TRUE (found version "2.0")
    -- Disabling ccache support
    -- Configuring done (56.9s)
    -- Generating done (1.5s)
    CMake Warning:
     Manually-specified variables were not used by the project:
    
       CMAKE_TOOLCHAIN_FILE
    
    -- Build files have been written to: E:/srcCode/glomap/build
  3. Build the project in Visual Studio 2019.

Errors: During the build process in Visual Studio 2019, I encountered the following linker errors:

Severity    Code    Description    Project    File    Line    Suppression State
Error    LNK2019    unresolved external symbol cholmod_start, referenced in function "int __cdecl Eigen::internal::cm_start<int>(struct cholmod_common_struct &)" (??$cm_start@H@internal@Eigen@@YAHAEAUcholmod_common_struct@@@Z)    glomap_main    E:\srcCode\glomap\build\glomap\glomap.lib(global_rotation_averaging.obj)    1    
Error    LNK2019    unresolved external symbol cholmod_finish, referenced in function "int __cdecl Eigen::internal::cm_finish<int>(struct cholmod_common_struct &)" (??$cm_finish@H@internal@Eigen@@YAHAEAUcholmod_common_struct@@@Z)    glomap_main    E:\srcCode\glomap\build\glomap\glomap.lib(global_rotation_averaging.obj)    1    
Error    LNK2019    unresolved external symbol cholmod_free_factor, referenced in function "int __cdecl Eigen::internal::cm_free_factor<int>(struct cholmod_factor_struct * &,struct cholmod_common_struct &)" (??$cm_free_factor@H@internal@Eigen@@YAHAEAPEAUcholmod_factor_struct@@AEAUcholmod_common_struct@@@Z)    glomap_main    E:\srcCode\glomap\build\glomap\glomap.lib(global_rotation_averaging.obj)    1    
Error    LNK2019    unresolved external symbol cholmod_free_dense, referenced in function "int __cdecl Eigen::internal::cm_free_dense<int>(struct cholmod_dense_struct * &,struct cholmod_common_struct &)" (??$cm_free_dense@H@internal@Eigen@@YA

HAEAPEAUcholmod_dense_struct@@AEAUcholmod_common_struct@@@Z)    glomap_main    E:\srcCode\glomap\build\glomap\glomap.lib(global_rotation_averaging.obj)    1    
Error    LNK2019    unresolved external symbol cholmod_analyze, referenced in function "struct cholmod_factor_struct * __cdecl Eigen::internal::cm_analyze<int>(struct cholmod_sparse_struct &,struct cholmod_common_struct &)" (??$cm_analyze@H@internal@Eigen@@YAPEAUcholmod_factor_struct@@AEAUcholmod_sparse_struct@@AEAUcholmod_common_struct@@@Z)    glomap_main    E:\srcCode\glomap\build\glomap\glomap.lib(global_rotation_averaging.obj)    1    
Error    LNK2019    unresolved external symbol cholmod_factorize_p, referenced in function "int __cdecl Eigen::internal::cm_factorize_p<int>(struct cholmod_sparse_struct *,double * const,int *,unsigned __int64,struct cholmod_factor_struct *,struct cholmod_common_struct &)" (??$cm_factorize_p@H@internal@Eigen@@YAHPEAUcholmod_sparse_struct@@QEANPEAH_KPEAUcholmod_factor_struct@@AEAUcholmod_common_struct@@@Z)    glomap_main    E:\srcCode\glomap\build\glomap\glomap.lib(global_rotation_averaging.obj)    1    
Error    LNK2019    unresolved external symbol cholmod_solve, referenced in function "struct cholmod_dense_struct * __cdecl Eigen::internal::cm_solve<int>(int,struct cholmod_factor_struct &,struct cholmod_dense_struct &,struct cholmod_common_struct &)" (??$cm_solve@H@internal@Eigen@@YAPEAUcholmod_dense_struct@@HAEAUcholmod_factor_struct@@AEAU2@AEAUcholmod_common_struct@@@Z)    glomap_main    E:\srcCode\glomap\build\glomap\glomap.lib(global_rotation_averaging.obj)    1    
Error    LNK1120    7 unresolved externals    glomap_main    E:\srcCode\glomap\build\glomap\Debug\glomap.exe    1    

Modification: I had to modify the file E:\myVcpkg\vcpkg\installed\x64-windows\include\Eigen\CholmodSupport to include the cholmod.h file from the correct path. The change I made is as follows:

Original:

extern "C" {
  #include <cholmod.h>
}

Modified:

extern "C" {
  #include <suitesparse/cholmod.h>
}

Without this modification, I encountered the following error:

Severity    Code    Description    Project    File    Line    Suppression State
Error    C1083    Cannot open include file: 'cholmod.h': No such file or directory    glomap    E:\myVcpkg\vcpkg\installed\x64-windows\include\Eigen\CholmodSupport    16    

Environment:

It seems that there are unresolved external symbols related to cholmod functions. Could you please provide guidance on how to resolve these linker errors?

Thank you!

alLiucb commented 1 month ago

Hey, I solved it! I added the include path for cholmod.h to the missing project as it was before the modifications. Then, I regenerated the solution, and it was successful. However, when running glomap.exe, I encountered some missing DLLs. I resolved this by copying the required DLLs from other locations.

ahojnnes commented 1 month ago

This should unblock the windows build: https://github.com/colmap/glomap/pull/45 - only tested under VS2022 though.