Native windows build of Garfield++

Been working on making garfield++ to compile as dynamic library on windows. Headers will still need to use __declspec(dllimport) on most imported symbols, but some examples can run now.

Tested with ifort.

1 Like

That’s great! Thanks so much. Do you think we could merge your changes to the main garfieldpp repository?

1 Like

Of course, but some places have hacks that may not be appropriate for normal compilation, need some work to make both compilation work.

Specifically, building megaboltz as dll on windows requires an export symbol table. I currently put that build file in megaboltz instead of make directory, and compile option of target_link_options(${libname} PRIVATE /DEF:${CMAKE_CURRENT_SOURCE_DIR}/magboltz.def) is used and replaced the unavailable target_compile_options(${libname} PRIVATE -std=legacy), and need to manually remove the /fpp flag unconditionally generated by cmake by editing cache.

Will work on conditionally choosing former options tomorrow, but the /fpp cannot be easily removed and I’m currently filing an issue at cmake repository:

Updated to be ready-to-build. Also added instruction of how to build in Non-windows and non-intel compiler platform should not be disturbed.

Currently uses intel compiler to build, since it’s native to the visual studio build system. But should be possible to use mingw gfortran to build.

Since the c abi used is the same (assuming they have same struct alignment), one should be able to generate the .lib required by msvc to link and preload dynamic libraries (without explicit dlopen or LoadLibrary).

A custom build step using a gfortran compiler will work like this:

  1. Compile using gfortran
  2. Custom build step, generate .lib from .dll
  3. Specify to link .lib into the executable in executable linker options

If the fortran runtime in turn relies on c-runtime, then binary copying on windows will become a bit tedious.

With some searches, it seems cmake already comes with a utility that does exactly this, thus does not need custom tool for this, will look into using this tomorrow:

Now the changes should be production ready, and should compile out of the box with correct envrionment variables set. Works with both gfortran and intel compilers.

A binary version of dependencies and megaboltz are uploaded to github release, should be able to choose from intel compilers and gfortran compiler. But since Garfield++ uses generated root dict file, and have absolute path in it, Garfield.dll itself is not portable and not uploaded.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.