1

I have built a simple CGAL example but when I run it, I get an error that gmp.dll was not found.

I am on Windows 10, using CMake and MSBuild and trying to build a simple sample CGAL C++ program.

I used vcpkg (with environment variable VCPKG_DEFAULT_TRIPLET set as x64-windows) to install CGAL via the following commands:

.\vcpkg.exe install cgal[qt] --recurse
vcpkg integrate install

The C++ code I'm using is copied exactly from a CGAL constrained 2d triangulation example and placed into main.cpp.

My CMakeLists.txt is as follows:

cmake_minimum_required(VERSION 3.1...3.15)

project(hello-world)

find_package(CGAL REQUIRED)

add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME} CGAL)

I make a build directory, move into it, and run cmake. When running cmake, I supply the variable -DCMAKE_TOOLCHAIN_FILE=<vcpkg_path>\scripts\buildsystems\vcpkg.cmake and use generator Visual Studio 16 2019. The command runs without issue. Here is a relevant piece of output:

-- Found GMP: <vcpkg_path>/installed/x64-windows/lib/gmp.lib

Next, I run MSBuild on the generated hello-world.sln file. Again, everything runs without issue, compilation and linking is successful. Here is some relevant info from the linking stage:

Link:
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\link.exe /ERRORREPORT:QUEUE /OU
  T:"<current_directory>\Debug\hello-world.exe" /INCREMENTAL /NOLOGO "<vcpkg_path>\installed\x64-windows\debug\lib\mpfr.lib" "<vcpkg_path>\installed\x64-wind
  ows\lib\gmp.lib" kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /
  MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"<current_directory>/Debug/hello-world.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"<current_directory>/Debug/hello-world.lib" /MACHINE:X64  /machine:x64 "hello-world.dir\Debug\main.obj"
  hello-world.vcxproj -> <current_directory>\Debug\hello-world.exe

Now, finally when I try to run hello-world.exe, I get the error:

The code execution cannot proceed because gmp.dll was not found. Reinstalling the program may fix this problem.

I come from a Linux background so I'm not entirely comfortable with Windows' shared library conventions. I understand that gmp.lib contains relevant info for gmp.dll like the entry point? Does it also hold information about where to find it? I've read that generally the .dll files should be located beside the .exe, if so, should CMake be doing this? If not, why wouldn't vcpkg install them to a system directory, or at least the toolchain file I supplied could point to the .dlls?

I can manually copy gmp.dll from the vcpkg bin directory into the same directory as my .exe, but that seems like only a workaround.

I have another question that's a bit more specific to the vcpkg buffs. Can I easily install CGAL so that GMP is linked statically rather than dynamically?

Victor Stone
  • 498
  • 5
  • 18
  • ***if so, should CMake be doing this?*** CMake on its own will not automatically do that for you. However you can script this behavior. vcpkg should do this for you if your own project uses CMake and the vcpkg toolchain file. – drescherjm May 26 '21 at 16:24
  • @drescherjm You said "vcpkg should do this for you". That is what I would expect, but that's not what is happening. I am using the vcpkg toolchain file when running cmake. – Victor Stone May 26 '21 at 16:32
  • 1
    My one guess is `CGAL` was built as header only and that is causing the dll dependency copy mechanism to not work. I believe it normally works by evaluating the dll dependencies of the produced binaries. This may be something to ask at the vcpkg github – drescherjm May 26 '21 at 17:00
  • 1
    On Windows, a dll needs to be in the current directory, in a PATH directory, or registered with regsvr32.exe. – stark May 26 '21 at 17:23

1 Answers1

0

Ok first of all there is a bug there. You are building debug and it links the release version of gmp. Since it is a C library it doesn't matter that much.

If you are using the VS IDE you might want to setup https://cmake.org/cmake/help/git-stage/prop_tgt/VS_DEBUGGER_ENVIRONMENT.html to add the VCPKG bin dir to PATH, alternativly you might run https://cmake.org/cmake/help/latest/command/file.html#get-runtime-dependencies to install any runtime dependencies into the build dir (vcpkg should normally do that with VCPKG_APPLOCAL_DEPS but maybe the configuration issue blocks it). Both things won't work if the dependency is just a plugin.

Alexander Neumann
  • 1,479
  • 8
  • 17