cyang-kth / fmm

Fast map matching, an open source framework in C++
https://fmm-wiki.github.io/
Apache License 2.0
875 stars 205 forks source link

Guide for building with MSVC on Windows and fixing DLL missing problem when running program #227

Open yxnchen opened 2 years ago

yxnchen commented 2 years ago

Hi, recently I try to install fmm on native Windows environment without Cygwin by following the instructions mentioned at this PR https://github.com/cyang-kth/fmm/pull/165. However, the instructions are not comprehensive for new guys on C++ like me. Finally, I successfully install the fmm program and its python binding with the help of Google. And here they are (modified from https://github.com/cyang-kth/fmm/pull/165#issue-785671958):

  1. Install MSVC (C++ tools or full Visual Studio set)
  2. Install CMake and SWIG
  3. Install vcpkg
    • If you are using 64-bit Anaconda Python like me, just add an environment variable VCPKG_DEFAULT_TRIPLET with value x64-windows. Then you don't need to specify the triplet when install dependencies at step4.
  4. Install dependencies with vcpkg: vcpkg install gdal boost-geometry boost-graph boost-serialization
    • I downloaded the latest vcpkg at this moment and just ran the install command above but encountering problem https://github.com/microsoft/vcpkg/issues/21696 .
    • Then I noticed the versioning control of vcpkg https://vcpkg.io/en/docs/examples/versioning.getting-started.html#version-1 and reverted to a previous commit to solve it. Here I share my vcpkg.json:
      {
      "name": "versions-test",
      "version": "1.0.0",
      "dependencies": [
      "boost-geometry",
      "boost-graph",
      "boost-serialization",
      {
          "name": "gdal",
          "version>=": "3.1.3"
      }
      ],
      "builtin-baseline": "60d7d91c7105a2ba821a450ea4ba336dfbf14719"
      }
    • Put it in the root directory of the project and you don't need to run the vcpkg install ... command as step6 will automatically do it for you.
    • Perhaps when vcpkg solve the build failure of some packages then we don't need to revert to a previous version anymore.
  5. mkdir build and cd build
  6. Generate project with CMake: cmake .. -DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake -DSWIG_EXECUTABLE=[path to swig.exe]
  7. Build with CMake: cmake --build . --parallel 4 --config Release
  8. Install with CMake: cmake --install . --config Release. (This step will require admin permission as the program will be installed to the default directory C:\Program Files\fmm)

Describe the bug After installing with CMake, the DLL missing problem is prompted when calling fmm.exe (ImportError: DLL load failed when importing fmm in Python).

I check the folder C:\Program Files\fmm\bin and don't find any DLL files. Then I copy all the DLL files in folder fmm\build\Release to it and problem solved.

Similarly, I copy the DLL files from fmm\build\python\Release to Lib\site-packages. However, the problem ImportError: DLL load failed in Python remained. Then I use Dependency Walker to check the DLL dependencies of the file Lib\site-packages\_fmm.pyd and find this: Dependency Walker Finally, I copy the FMMLIB.dll file from fmm\build\Release to Lib\site-packages and problem solved.

My suggestion is whether is possible to change CMakeLists.txt such that the generated DLL files will be copied to the right folders when installing.

Expected behavior Like https://fmm-wiki.github.io/docs/installation/windows.html#verfication-of-installation after cmake --install without manually copying DLL files.

Screenshots