Skip to content

Improve mergestaticlibs #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jschueller
Copy link
Contributor

@jschueller jschueller commented May 19, 2025

Use linux part only on linux platforms
Should fix #180

@jschueller jschueller marked this pull request as ready for review May 19, 2025 07:04
Comment on lines +93 to 98
else()
# only works with static third-party libs
foreach(libtarget ${libs})
target_sources(${outlib} PUBLIC $<TARGET_OBJECTS:${libtarget}>)
endforeach()
endif()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this a bit more, and how it solves the Mingw issue in #192?

  1. Reading the doc it's not clear to me how it's valid that target_sources(...) can accept object files. To me it looks like it expects .c and .h files, and that one should use target_link_libraries(...) with the object files?
  2. How can we use $<TARGET_OBJECTS:...> if libtarget is not specified as add_library(... OBJECT)? At least I don't see that we specify it as OBJECT.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems #192 build failed because it did not have the ls command to list object files

I tried several things including creating an intermediate OBJECT library but it did not work but curiously target_sources worked, so seems I have to dig on the cmake side

Comment on lines +93 to +97
else()
# only works with static third-party libs
foreach(libtarget ${libs})
target_sources(${outlib} PUBLIC $<TARGET_OBJECTS:${libtarget}>)
endforeach()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal test of the MinGW installation shows that there are some issues, likely expat (and possibly other libs are not merged or found):

Output...
set -eu; \
	cd Test/test_installation; \
	rm -rf build && mkdir -p build; \
	cd build; \
	cmake -DFMIL_HOME=/c/<...>/install_mingw_w64 -G "MSYS Makefiles" ..; \
	cmake --build .; \
	ctest 

...

[ 50%] Linking C executable main.exe
C:/<...>/install_mingw_w64/lib/libfmilib.a(fmi_xml_context.c.obj):fmi_xml_context.c:(.text+0xa7): undefined reference to `XML_ParserFree'
C:/<...>/install_mingw_w64/lib/libfmilib.a(fmi_xml_context.c.obj):fmi_xml_context.c:(.text+0x115): undefined reference to `XML_StopParser'
C:/<...>/install_mingw_w64/lib/libfmilib.a(fmi_xml_context.c.obj):fmi_xml_context.c:(.text+0x2d3): undefined reference to `XML_ParserFree'
C:/<...>/install_mingw_w64/lib/libfmilib.a(fmi_xml_context.c.obj):fmi_xml_context.c:(.text+0x2e2): undefined reference to `XML_ParserCreate_MM'
C:/<...>/install_mingw_w64/lib/libfmilib.a(fmi_xml_context.c.obj):fmi_xml_context.c:(.text+0x2fd): undefined reference to `XML_SetUserData'
C:/<...>/install_mingw_w64/lib/libfmilib.a(fmi_xml_context.c.obj):fmi_xml_context.c:(.text+0x313): undefined reference to `XML_SetElementHandler'
C:/<...>/install_mingw_w64/lib/libfmilib.a(fmi_xml_context.c.obj):fmi_xml_context.c:(.text+0x322): undefined reference to `XML_SetCharacterDataHandler'
C:/<...>/install_mingw_w64/lib/libfmilib.a(fmi_xml_context.c.obj):fmi_xml_context.c:(.text+0x396): undefined reference to `XML_Parse'
C:/<...>/install_mingw_w64/lib/libfmilib.a(fmi_xml_context.c.obj):fmi_xml_context.c:(.text+0x426): undefined reference to `XML_GetErrorCode'
C:/<...>/install_mingw_w64/lib/libfmilib.a(fmi_xml_context.c.obj):fmi_xml_context.c:(.text+0x42d): undefined reference to `XML_ErrorString'
C:/<...>/install_mingw_w64/lib/libfmilib.a(fmi_xml_context.c.obj):fmi_xml_context.c:(.text+0x438): undefined reference to `XML_GetCurrentLineNumber'
C:/<...>/install_mingw_w64/lib/libfmilib.a(fmi_xml_context.c.obj):fmi_xml_context.c:(.text+0x476): undefined reference to `XML_ParserFree'
C:/<...>/install_mingw_w64/lib/libfmilib.a(fmi_xml_context.c.obj):fmi_xml_context.c:(.text+0x22b): undefined reference to `XML_StopParser'
C:/<...>/install_mingw_w64/lib/libfmilib.a(unzip.c.obj):unzip.c:(.text+0x1ce5): undefined reference to `inflateEnd'
C:/<...>/install_mingw_w64/lib/libfmilib.a(unzip.c.obj):unzip.c:(.text+0x2b55): undefined reference to `inflateEnd'
C:/<...>/install_mingw_w64/lib/libfmilib.a(unzip.c.obj):unzip.c:(.text+0x2bee): undefined reference to `inflateInit2_'
C:/<...>/install_mingw_w64/lib/libfmilib.a(unzip.c.obj):unzip.c:(.text+0x2e98): undefined reference to `inflate'
C:/<...>/install_mingw_w64/lib/libfmilib.a(unzip.c.obj):unzip.c:(.text+0x2eed): undefined reference to `crc32'
C:/<...>/install_mingw_w64/lib/libfmilib.a(unzip.c.obj):unzip.c:(.text+0x2fb1): undefined reference to `crc32'
C:/<...>/install_mingw_w64/lib/libfmilib.a(unzip.c.obj):unzip.c:(.text+0x3205): undefined reference to `inflateEnd'
collect2.exe: error: ld returned 1 exit status

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you using an external, dynamic expat lib ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Building with bundled expat:

mkdir -p build_mingw_w64
cd build_mingw_w64 && \
		cmake -DCMAKE_INSTALL_PREFIX=../install_mingw_w64 \
			-DFMILIB_GENERATE_DOXYGEN_DOC=0 \
			-DFMILIB_BUILD_WITH_STATIC_RTLIB=0 \
			-DFMILIB_BUILD_TESTS=1 \
			-DFMILIB_TEST_LOCALE=1  \
			-DCMAKE_BUILD_TYPE=Release \
			-DCMAKE_C_FLAGS="-m64" -DCMAKE_CXX_FLAGS="-m64" -DCMAKE_SHARED_LINKER_FLAGS="-m64" -DCMAKE_EXE_LINKER_FLAGS="-m64" \
			-G "MSYS Makefiles" \
			../.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Config.cmake/mergestaticlibs.cmake do not work on mingw.
2 participants