Linking dependencies statically

Has anyone managed to compile igraph into a shared library, and link dependencies statically?

This has been a problem for me on Windows when using MSYS2. Normally, anything compiled with MSYS2’s MinGW will depend on libgcc_s_seh-1.dll, libstdc++-6.dll, libwinpthread-1.dll. One can verify using Dependency Walker whether these dependencies are present.

I’ve been struggling to get rid of these. StackOverflow says that one can use the compiler flags -static -static-libgcc -static-libstdc++ to avoid these dependencies. I tried this using a minimal C++ example program that was compiled as

g++ -static -static-libgcc -static-libstdc++ -shared -o foo.dll foo.cpp

and it appears to work.

But if I compile igraph as follows, it does not work:

export CFLAGS="-static-libgcc -static-libstdc++" CXXFLAGS="-static-libgcc -static-libstdc++" LDFLAGS="-static-libgcc -static-libstdc++"

./configure --disable-gmp --disable-graphml --with-pic

make

I use --disable-gmp --disable-graphml to keep things as minimal as possible. If I look at the linking step of the output, I see libtool being called, and the above flags are indeed passed to it. But then if I open libigraph-0.dll with depwalker, I still see a dependency on libstdc++-6.dll.

I think that autotools and libtool, which I am not familiar with, somehow prevent static linking here. Unfortunately, I do not have sufficient technical knowlegde to udnerstand what is going on, and I could not solve this even after spending a considerable amount of time googling and searching StackOverflow.

For a high-level interface, having these dependencies is not okay because another package may load an incompatible version of the same DLLs.

@tamas, will cmake help with this eventually?

I haven’t succeeded in this either back in the past, and I remember that I also had problems linking to the C++ standard library statically - not only in igraph, but in other projects as well. Certain sources on the Internet claim that it is not possible to link to the GNU Standard C++ Library statically at all - you need to use libmusl instead. In the end I settled on an almost-fully-static build in most of my projects where only the standard C++ library was linked to dynamically. cmake is totally unrelated to this.