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?