https://bugs.openldap.org/show_bug.cgi?id=9226
Bug ID: 9226 Summary: MinGW build fails to link rewrite program with --enable-dynamic Product: OpenLDAP Version: 2.5 Hardware: All OS: All Status: UNCONFIRMED Severity: normal Priority: --- Component: build Assignee: bugs@openldap.org Reporter: ryan@openldap.org Target Milestone: ---
/bin/sh ../../libtool --mode=link cc -g -O2 -o rewrite rewrite.o parse.o librewrite.a ../../libraries/libldap_r/libldap_r.la ../../libraries/liblber/liblber.la ../../libraries/liblutil/liblutil.a -lregex -lws2_32 libtool: link: cc -g -O2 -o .libs/rewrite rewrite.o parse.o librewrite.a ../../libraries/libldap_r/.libs/libldap_r.dll.a /home/ryan/openldap/libraries/liblber/.libs/liblber.dll.a ../../libraries/liblber/.libs/liblber.dll.a ../../libraries/liblutil/liblutil.a -lregex -lws2_32 -L/mingw64/lib C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../../libraries/liblutil/liblutil.a(utils.o): in function `lutil_str2bin': C:\msys64\home\ryan\openldap\libraries\liblutil/utils.c:933: undefined reference to `__imp_ber_memfree_x' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\home\ryan\openldap\libraries\liblutil/utils.c:887: undefined reference to `__imp_ber_memalloc_x' collect2.exe: error: ld returned 1 exit status make[2]: *** [Makefile:292: rewrite] Error 1
I think this is caused by the order of libraries on the link line. MinGW's import libraries (.dll.a) behave like static libraries with one .o per function, so liblutil.a should come before liblber.dll.a. I guess it doesn't occur on UNIX because the shared libraries are scanned differently. It doesn't occur with static linking because entire objects are linked and liblber.a/memory.o is already pulled in by libldap.
N.B.: RE24 with --enable-dynamic fails to link liblber; the error looks superficially similar but it is not the same. RE24's issue is a libtool bug, already fixed in master by upgrading libtool.