I have come across this post years later since it's listed very high in google search results when searching for "Occt static compilation" and since there is no definitive answer I thought I add this.
In the end what did it for me was using a different linker, in my case lld instead of ld. lld is capable of figuring out the dependency order by itself, it seems. Here here is some further reading [1,2].
without CMake
Compile main.cpp into object.
$ g++ -std=c++11 -c -I<path>/OCCT-7_8_0/install-gnu-static-release/include/opencascade/ main.cpp
Link executable.
$ g++ -static -fuse-ld=lld -L<path>/OCCT-7_8_0/install-gnu-static-release/lib/ -lTKBool -lTKDECascade -lTKDESTEP -lTKFillet -lTKHLR -lTKOffset -lTKShHealing -lTKV3d -lTKXmlL -lTKBinL -lTKBRep -lTKDEGLTF -lTKDESTL -lTKG2d -lTKLCAF -lTKOpenGl -lTKStd -lTKVCAF -lTKXmlTObj -lTKBinTObj -lTKCAF -lTKDEIGES -lTKDEVRML -lTKG3d -lTKMath -lTKPrim -lTKStdL -lTKXCAF -lTKXmlXCAF -lTKBinXCAF -lTKCDF -lTKDEOBJ -lTKernel -lTKGeomAlgo -lTKMesh -lTKRWMesh -lTKTObj -lTKXMesh -lTKXSBase -lTKBO -lTKDE -lTKDEPLY -lTKFeat -lTKGeomBase -lTKMeshVS -lTKService -lTKTopAlgo -lTKXml -std=c++11 -o main.out main.o
-static makes sure you get the standard libraries such as libm statically as well. -fuse-ld=lld sets the new linker. In my case I had to install it first.
$ sudo apt install lld
with cmake
The same can be done though CMake.
This is the CMakeLists.txt.
cmake_minimum_required(VERSION 3.13.0)
include(CMakePrintHelpers)
project(STEP_IGES_to_STL)
add_executable(${PROJECT_NAME} main.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC "${OCCT_DIR}/include/opencascade/")
target_link_directories(${PROJECT_NAME} PUBLIC "${OCCT_DIR}/lib")
target_link_libraries(${PROJECT_NAME} PUBLIC
"TKBin" "TKCAF" "TKDEPLY" "TKG2d" "TKMesh" "TKShHealing" "TKXCAF"
"TKBinL" "TKCDF" "TKDESTEP" "TKG3d" "TKMeshVS" "TKStd" "TKXMesh"
"TKBinTObj" "TKDE" "TKDESTL" "TKGeomAlgo" "TKOffset" "TKStdL" "TKXml"
"TKBinXCAF" "TKDECascade" "TKDEVRML" "TKGeomBase" "TKOpenGl" "TKTObj" "TKXmlL"
"TKBO" "TKDEGLTF" "TKernel" "TKHLR" "TKPrim" "TKTopAlgo" "TKXmlTObj"
"TKBool" "TKDEIGES" "TKFeat" "TKLCAF" "TKRWMesh" "TKV3d" "TKXmlXCAF"
"TKBRep" "TKDEOBJ" "TKFillet" "TKMath" "TKService" "TKVCAF" "TKXSBase"
)
install(TARGETS ${PROJECT_NAME})
And this is the command invoked from inside the build dir.
$ cmake -DCMAKE_CXX_FLAGS="-std=c++11 -fuse-ld=lld" -DCMAKE_INSTALL_PREFIX=<install-dir> -DOCCT_DIR=<path>/OCCT-7_8_0/install-gnu-static-release/ -S .. -B .
Note: we are not setting the actual linker in CMake since the linker is usually called through the compiler. Instead we tell the compiler what linker to use. See [3]
[1] https://stackoverflow.com/questions/45135
[2] https://stackoverflow.com/questions/34164594
[3] https://stackoverflow.com/a/64174822