Issue 9226 - MinGW build fails to link rewrite program with --enable-dynamic
Summary: MinGW build fails to link rewrite program with --enable-dynamic
Status: VERIFIED FIXED
Alias: None
Product: OpenLDAP
Classification: Unclassified
Component: build (show other issues)
Version: 2.5.4
Hardware: All All
: --- normal
Target Milestone: 2.5.0
Assignee: OpenLDAP project
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-17 02:32 UTC by Ryan Tandy
Modified: 2020-10-14 21:21 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Ryan Tandy 2020-04-17 02:32:05 UTC
/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.
Comment 1 Quanah Gibson-Mount 2020-04-17 03:42:54 UTC
  • db404baf 
by Ryan Tandy at 2020-04-16T19:35:53-07:00 
ITS#9226 Fix link order for rewrite program on MinGW