Hi, I was just wondering if fpm could be used to build a dll/so as a library output? I have seen how to generate a static lib but haven’t seen in the manuals any info regarding dynamic libs.
Today I manage to do it with CMake. Would like to see if fpm could help doing it in a more “clean” manner?
Last time I checked (which was a while back) it couldn’t. Probably a worthwhile feature to add if not present.
Note there should already be a GitHub issue for this.
Not that fpm shouldn’t at some point be able to do it for you, but would this work for your needs?
I did it by hand with a simple file and it works, I also saw here how to do it with ifort https://community.intel.com/t5/Intel-Fortran-Compiler/Creating-dll-from-fortran-file/m-p/1182026 from a single source file. I guess that is more or less what CMake is currently doing for me? the goal was to see if it could be easily doable within a fpm build. Just out of curiosity
I would like to share a very simple Makefile if you need to create a shared library from the static one generated by fpm.
fpm is used to build the static library and the latter is copied to the root of the build folder. Then it is used to create the shared library with gfortran according to the defined PLATFORM. You can add additional target according to your needs.
$(LIBNAME): build copy_static shared copy_shared
fpm build --profile=release
cp $(shell find ./build -type f -name lib$(LIBNAME).a) $(BUILD_DIR)
gfortran -shared -o $(BUILD_DIR)/lib$(LIBNAME).so -Wl,--whole-archive $(BUILD_DIR)/lib$(LIBNAME).a -Wl,--no-whole-archive
gfortran -dynamiclib -install_name @rpath/lib$(LIBNAME).dylib -static-libgfortran -static-libquadmath -static-libgcc -o $(BUILD_DIR)/lib$(LIBNAME).dylib -Wl,-all_load $(BUILD_DIR)/lib$(LIBNAME).a -Wl,-noall_load
gfortran -shared -static -o $(BUILD_DIR)/lib$(LIBNAME).dll -Wl,--out-implib=$(BUILD_DIR)/lib$(LIBNAME).dll.a,--export-all-symbols,--enable-auto-import,--whole-archive $(BUILD_DIR)/lib$(LIBNAME).a -Wl,--no-whole-archive
Welcome @mskocic and thanks for the Makefile I haven’t check the inners of how fpm does its magic but would be interesting if something like this could be added
I didn’t look in details at the fpm internals but I assume it might be challenging to deal with rpath according to the platforms and the whole set of options for the different available compilers. Windows is, in my point of view, always a special case where there is a ton of specific options ( ).