MinGW and static linking

Hello OCCT Users !

I've smoothly compiled latest OpenCascade with MinGW GCC9.2.0  with Win64 target.

So I got two folders : win64\gcc\bin containing  libTKxxx.dll files    and   win64\gcc\lib  containing libTKxxx.dll.a   files.

I thought  that .dll.a  files would be fine to statically link Opencascade to my app.

I'm compiling my app with flag    -Wl,-Bstatic    so all libraries are statically linked : it works fine for libstdc++,  wxwidgets, ...

But I realized that, although static flag, OpenCascade is still dynamically linked : the app exe file requires   win64\gcc\bin    in standard  PATH to find required DLLs ?

Here is the linker output :

-Wl,-Bstatic -static-libstdc++ -static-libgcc -static -s -m64  -lwxsqlite3_msw31u -lwxmsw31u_html -lwxmsw31u_adv -lwxmsw31u_core -lwxbase31u -lwxmsw31u_aui -lwxmsw31u_gl -lwxmsw31u_propgrid -lwxmsw31u_ribbon -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregexu -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lshlwapi -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lversion -lwsock32 -lwininet -loleacc -lodbc32 -luxtheme -lopengl32 -lglu32 -lTKBin.dll -lTKBinL.dll -lTKBinTObj.dll -lTKBinXCAF.dll -lTKBO.dll -lTKBool.dll -lTKBrep.dll -lTKCAF.dll -lTKCDF.dll -lTKDraw.dll -lTKernel.dll -lTKFeat.dll -lTKFillet.dll -lTKG2d.dll -lTKG3d.dll -lTKGeomAlgo.dll -lTKGeomBase.dll -lTKHLR.dll -lTKIGES.dll -lTKLCAF.dll -lTKMath.dll -lTKMesh.dll -lTKMeshVS.dll -lTKOffset.dll -lTKOpenGl.dll -lTKPrim.dll -lTKQADraw.dll -lTKRWMesh.dll -lTKService.dll -lTKShHealing.dll -lTKStd.dll -lTKStdL.dll -lTKSTEP.dll -lTKSTEP209.dll -lTKSTEPAttr.dll -lTKSTEPBase.dll -lTKSTL.dll -lTKTObj.dll -lTKTObjDRAW.dll -lTKTopAlgo.dll -lTKTopTest.dll -lTKV3D.dll -lTKVCAF.dll -lTKViewerTest.dll -lTKVRML.dll -lTKXCAF.dll -lTKXDEDRAW.dll -lTKXDEIGES.dll -lTKXDESTEP.dll -lTKXMesh.dll -lTKXml.dll -lTKXmlL.dll -lTKXmlTObj.dll -lTKXmlXCAF.dll -lTKXSBase.dll -lTKXSDRAW.dll -mwindows

 

Any idea ?

Thanks

John

 

 

Kirill Gavrilov's picture

I got two folders : win64\gcc\bin containing  libTKxxx.dll files    and   win64\gcc\lib  containing libTKxxx.dll.a   files
I thought  that .dll.a  files would be fine to statically link Opencascade to my app. 

This is a wrong assumption. .dll.a files are for a linking to .dll libraries, not for static linking.
On Linux platforms .so files could be directly linked and .a files are normally for static linking.
But on Windows, .dll files do not contain import information necessary for linking them, so that there are always .lib (or .a in case of MinGW) files in both cases - for dynamic and static linking, but these .lib and .a files will be different!

Static linking to OCCT requires rebuilding OCCT itself for generating static libraries instead of shared by passing appropriate flags to CMake.
 -D BUILD_LIBRARY_TYPE:STRING="Static"

You should be careful statically linking to LGPL libraries like OCCT (normally, shared libraries are used for proprietary applications).

John Whitaker's picture

Understood !

So, I'll keep standard dynamic linking for  OCCT.  Much easier this way.

Thanks again Kiril !