Compiling and Linking to nglib


I am attempting to compile netgen’s nglib with OCCT for usage as a shared library on Windows. I want to be able to mesh a STEP file from within an occt based application using netgen. I run into an issue where when trying to link from my code to nglib, no symbols are defined. Here is an example error from the linker (it is happening for all symbols defined in nglib.h):

[build] my_target.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl Ng_Meshing_Parameters::Ng_Meshing_Parameters(void)" (__imp_??0Ng_Meshing_Parameters@@QEAA@XZ) referenced in function main [C:\path\to\my\target\my_target.vcxproj]

I am able to compile netgen using CMake and Visual Studio 17 2022. I confirmed that the dll and lib files contain the symbols I’m trying to use.

Here are the steps I took to get to this issue:

  1. clone netgen repo into netgen directory
  2. make directory netgen\build and cd into it
  3. set the following options in the top level CMakeLists.txt:
option( USE_NATIVE_ARCH  "build for native cpu architecture" ON)
option( USE_GUI     "build with GUI" OFF )
option( USE_PYTHON  "build with python interface" OFF )
cmake_dependent_option( PREFER_SYSTEM_PYBIND11  "Use system wide PyBind11" OFF "USE_PYTHON" OFF)
option( USE_MPI     "enable mpi parallelization" OFF )
option( USE_MPI4PY  "enable mpi4py interface" OFF )
option( USE_OCC     "build with OpenCascade geometry kernel interface" ON)
option( USE_STLGEOM     "build with STL geometry support" ON)
option( USE_CSG     "build with CSG kernel" ON)
option( USE_INTERFACE     "build nginterface" ON)
option( USE_GEOM2D     "build 2d geometry kernels" ON)
option( USE_JPEG    "enable snapshots using library libjpeg" OFF )
option( USE_MPEG    "enable video recording with FFmpeg, uses libavcodec" OFF )
option( USE_CGNS    "enable CGNS file read/write support" OFF )
option( USE_NUMA         "compile with NUMA-aware code")
option( INTEL_MIC        "cross compile for intel xeon phi")
option( INSTALL_PROFILES "install environment variable settings to /etc/profile.d" OFF )
option( USE_CCACHE       "use ccache")
option( USE_INTERNAL_TCL "Compile tcl files into the code and don't install them" OFF)
option( ENABLE_UNIT_TESTS "Enable Catch unit tests")
option( ENABLE_CPP_CORE_GUIDELINES_CHECK "Enable cpp core guideline checks on ngcore" OFF)
option( USE_SPDLOG "Enable spd log logging" OFF)
option( DEBUG_LOG "Enable more debug output (may increase computation time) - only works with USE_SPDLOG=ON" OFF)
option( CHECK_RANGE "Check array range access, automatically enabled if built in debug mode" OFF)
option( BUILD_STUB_FILES "Build stub files for better autocompletion" OFF)
option( BUILD_FOR_CONDA "Link python libraries only to executables" OFF)
option( USE_SUPERBUILD       "build dependencies automatically" ON)
option( TRACE_MEMORY     "Enable memory tracing" OFF)
  1. cmake “…” -DCMAKE_INSTALL_PREFIX=“install” -G “Visual Studio 17 2022”
  2. cmake --build . --config Release --target install
  3. copy contents of install directory into my repo under my_repo\include\netgen
  4. add the following lines to my cmake file:
find_package(nglib NAMES Netgen netgen nglib Nglib REQUIRED HINTS ${CMAKE_SOURCE_DIR}/include/netgen/cmake/)
add_executable(my_target "")
set_property(TARGET my_target PROPERTY CXX_STANDARD 20)
target_link_libraries(my_target PRIVATE nglib)
  1. I configure and build with these cmake commands:
cmake -Bc:/path/to/my/repo/out/build -G "Visual Studio 17 2022" -A x64
cmake --build c:/path/to/my/repo/out/build --config Debug --target my_target

which finally leads to the error described above.

Does anyone have any ideas what could be missing/what mistake I am making? Alternatively, can anyone point me to a guide to build and use nglib on windows?

Thanks in advance.