BrunoLevy / geogram

a programming library with geometric algorithms
Other
1.8k stars 122 forks source link

How to build the dynamic libraries (to run mesh manifold harmonics) on Windows? #165

Closed megawattfs closed 1 month ago

megawattfs commented 1 month ago

I am trying to build geogram on Windows to use functions from mesh_manifold_harmonics in a C++ DLL plugin. I downloaded version 1.9.0 from the releases page, ran configure.bat to generate the Visual Studio solution, and built the static libraries (note: I changed to vs2017 toolchain and /MD runtime library to match the plugin that depends on geogram). When I ran the application, it aborted. After tracing, I see that nlOpenDLL is not implemented for Windows static libraries and only works if GEO_DYNAMIC_LIBS is defined.

I tried to build the dynamic libraries, first by editing the VS property pages to make the target a dll and define GEO_DYNAMIC_LIBS, then by adding the following to the CMakeLists.txt files for each library:

option(BUILD_SHARED_LIBS "Build shared libraries" ON)
if(BUILD_SHARED_LIBS)
    add_definitions(-DGEO_DYNAMIC_LIBS)
endif()

But I keep getting compiler error C2491 "definition of dllimport not allowed" in all libraries, even though geogram_EXPORTS should be defined, so those should be dllexports, not imports. I'm confused about how to specify build settings when using both CMake and Visual Studio. I noticed my changes to the VS project properties are getting erased because of CMake.

In summary, how can I build the libraries such that mesh_manifold_harmonics works on Windows?

BrunoLevy commented 1 month ago

Hello, You need to create in the geogram sourcetree a file CMakeOptions.txt with the following content:

set(VORPALINE_PLATFORM Win-vs-dynamic-generic)
set(GEOGRAM_LIB_ONLY OFF)

Then restart configure.bat then it will generate a VS project with dynamic libs and the Manifold Harmonics demo will work.

(see geogram/cmake/options for example of CMakeOptions.txt files)

megawattfs commented 1 month ago

That worked, thanks!

BrunoLevy commented 1 month ago

Thank you for letting me know. (I've added an entry in the FAQ)