I am trying to follow the answer given here to combine multiple static libraries into a single archive under MinGW64. Specifically, I use CMake and specify the following command:
add_custom_command(
OUTPUT ${COMBINED_CORE_LIB_NAME}
COMMAND ${AR} -crs ${COMBINED_CORE_LIB_NAME} ${CORE_LIB_TARGET_FILES}
DEPENDS ${DILIGENT_CORE_INSTALL_LIBS_LIST}
COMMENT "Combining core libraries..."
)
Also, following the recommendation from here, I do not use stock ar, but rather cross ar:
find_program(AR NAMES x86_64-w64-mingw32-gcc-ar)
However, no matter what I do, ar refuses to generate index and every time I am trying to link against the produced library, I get this error:
error adding symbols: Archive has no index; run ranlib to add one
Running ranlib as suggested either stock one or x86_64-w64-mingw32-gcc-ranlib makes no difference.
I spent 15 minutes to make this work with MSVC and lib.exe and have been struggling for 8 hours with MinGW. Any suggestion would be highly appreciated.
[Edit]: It turned out that this problem is not really specific to MinGW and also happens on Linux in a very similar fashion.