11 Adding Shared Support to Packages
wolfy1339 edited this page 2019-10-07 00:39:05 -04:00

MXE is trying to support as many shared packages as possible. For well-packaged upstream tarballs, this task is very easy; for more exotic build systems or those with bugs, you'll have to figure something out yourself.

Always try to build and see if the results are indeed shared.

Autotools package

In most cases (for packages using libtool), you can simply change this (or something close to this):

--host='$(TARGET)' \
--build='$(BUILD)'
--prefix='$(PREFIX)/$(TARGET)' \
--disable-shared \
--enable-static

to

$(MXE_CONFIGURE_OPTS)

and you should be fine.

Troubleshoot

These are some common problems with autotools and how to identify and fix them.

Missing -no-undefined

This problem usually causes static libraries to be built even when shared is declared.

On Windows, libtool needs -no-undefined to be able to link shared DLLs. Many projects are already forcing -no-undefined, but some are not. If this is the problem, the log should show something like this (extracted from apr log):

libtool: link: warning: undefined symbols not allowed in i686-pc-mingw32.shared shared libraries

If this happens, simply add LDFLAGS=-no-undefined to the make command, and it should fix the problem. See commit 056f001 for an example.

Linking to Static-only library

This problem usually causes static libraries to be built even when shared is declared.

Another common problem occurs when a library tries to link to a static-only library, such as libSDLmain, libSDL2main, and libmingw32. The log shows something like this (occurred when I was trying to add shared support to sdl2_gfx):

*** Warning: This system can not link to static lib archive /home/timothy_gu/mxe/usr/i686-w64-mingw32.shared/lib/libSDL2main.la.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have.

*** Warning: linker path does not have real file for library -lmingw32.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libmingw32 and none of the candidates passed a file format test
*** using a file magic. Last file checked: /home/timothy_gu/mxe/usr/i686-w64-mingw32.shared/lib/libmingw32.a
*** The inter-library dependencies that have been dropped here will be
*** automatically added whenever a program is linked with this library
*** or is declared to -dlopen it.

*** Since this library must not contain undefined symbols,
*** because either the platform does not support them or
*** it was explicitly requested with -no-undefined,
*** libtool will only create a static version of it.

You will need to patch the package not to link to the offending libraries to fix this bug. If that is not possible, you will have to give up the attempt to convert the package to shared. For this particular package, see my fix here: 0656ed0 and b4f2887 (it uses a sed command to explicitly filter out the bad libraries).

Pre-commit checklist

Before you commit the changes, always use these steps to check if the conversion process is correct. Here, I will use package libwebp as an example. Package libwebp contains four libraries: libwebp, libwebpdecoder, libwebpdemux, and libwebpmux.

  1. Try building both shared and static to make sure no FTBFS occurs.
  2. Make sure static build only has static libraries. E.g. correct build:
timothy_gu@ubuntu-lenovo:~/mxe/usr$ find -name *libwebp*
./i686-w64-mingw32.static/lib/libwebpdemux.la
./i686-w64-mingw32.static/lib/libwebpdecoder.la
./i686-w64-mingw32.static/lib/libwebpmux.la
./i686-w64-mingw32.static/lib/pkgconfig/libwebp.pc
./i686-w64-mingw32.static/lib/pkgconfig/libwebpdecoder.pc
./i686-w64-mingw32.static/lib/pkgconfig/libwebpmux.pc
./i686-w64-mingw32.static/lib/pkgconfig/libwebpdemux.pc
./i686-w64-mingw32.static/lib/libwebp.a         <--- static
./i686-w64-mingw32.static/lib/libwebpdecoder.a  <--- static
./i686-w64-mingw32.static/lib/libwebpmux.a      <--- static
./i686-w64-mingw32.static/lib/libwebpdemux.a    <--- static
./i686-w64-mingw32.static/lib/libwebp.la
./i686-w64-mingw32.static/installed/libwebp

Wrong build:

timothy_gu@ubuntu-lenovo:~/mxe/usr$ find -name *libwebp*
./i686-w64-mingw32.static/bin/libwebp-5.dll        <--- shared, WRONG
./i686-w64-mingw32.static/bin/libwebpdecoder-1.dll <--- shared, WRONG
./i686-w64-mingw32.static/bin/libwebpmux-1.dll     <--- shared, WRONG
./i686-w64-mingw32.static/bin/libwebpdemux-1.dll   <--- shared, WRONG
./i686-w64-mingw32.static/lib/libwebpdemux.la
./i686-w64-mingw32.static/lib/libwebpdecoder.la
./i686-w64-mingw32.static/lib/libwebpmux.la
./i686-w64-mingw32.static/lib/pkgconfig/libwebp.pc
./i686-w64-mingw32.static/lib/pkgconfig/libwebpdecoder.pc
./i686-w64-mingw32.static/lib/pkgconfig/libwebpmux.pc
./i686-w64-mingw32.static/lib/pkgconfig/libwebpdemux.pc
./i686-w64-mingw32.static/lib/libwebp.a         <--- static
./i686-w64-mingw32.static/lib/libwebpdecoder.a  <--- static
./i686-w64-mingw32.static/lib/libwebpmux.a      <--- static
./i686-w64-mingw32.static/lib/libwebpdemux.a    <--- static
./i686-w64-mingw32.static/lib/libwebp.dll.a         <--- shared import lib, WRONG
./i686-w64-mingw32.static/lib/libwebpdecoder.dll.a  <--- shared import lib, WRONG
./i686-w64-mingw32.static/lib/libwebpmux.dll.a      <--- shared import lib, WRONG
./i686-w64-mingw32.static/lib/libwebpdemux.dll.a    <--- shared import lib, WRONG
./i686-w64-mingw32.static/lib/libwebp.la
./i686-w64-mingw32.static/installed/libwebp
  1. Make sure an import library (.dll.a) is built and installed to lib/ in shared mode:

    E.g. correct build:

timothy_gu@ubuntu-lenovo:~/mxe/usr$ find -name *libwebp*
./i686-pc-mingw32.shared/lib/libwebpdemux.la
./i686-pc-mingw32.shared/lib/libwebpmux.dll.a      <--- import lib
./i686-pc-mingw32.shared/lib/libwebpdecoder.la
./i686-pc-mingw32.shared/lib/libwebpdecoder.dll.a  <--- import lib
./i686-pc-mingw32.shared/lib/libwebpmux.la
./i686-pc-mingw32.shared/lib/libwebpdemux.dll.a    <--- import lib
./i686-pc-mingw32.shared/lib/pkgconfig/libwebp.pc
./i686-pc-mingw32.shared/lib/pkgconfig/libwebpdecoder.pc
./i686-pc-mingw32.shared/lib/pkgconfig/libwebpmux.pc
./i686-pc-mingw32.shared/lib/pkgconfig/libwebpdemux.pc
./i686-pc-mingw32.shared/lib/libwebp.dll.a         <--- import lib
./i686-pc-mingw32.shared/lib/libwebp.la
./i686-pc-mingw32.shared/installed/libwebp
./i686-pc-mingw32.shared/bin/libwebpmux-1.dll
./i686-pc-mingw32.shared/bin/libwebpdemux-1.dll
./i686-pc-mingw32.shared/bin/libwebp-5.dll
./i686-pc-mingw32.shared/bin/libwebpdecoder-1.dll

Wrong build:

timothy_gu@ubuntu-lenovo:~/mxe/usr$ find -name *libwebp*
./i686-pc-mingw32.shared/lib/libwebpdemux.la
./i686-pc-mingw32.shared/lib/libwebpdecoder.la
./i686-pc-mingw32.shared/lib/libwebpmux.la
./i686-pc-mingw32.shared/lib/pkgconfig/libwebp.pc
./i686-pc-mingw32.shared/lib/pkgconfig/libwebpdecoder.pc
./i686-pc-mingw32.shared/lib/pkgconfig/libwebpmux.pc
./i686-pc-mingw32.shared/lib/pkgconfig/libwebpdemux.pc
./i686-pc-mingw32.shared/lib/libwebp.la
./i686-pc-mingw32.shared/installed/libwebp
./i686-pc-mingw32.shared/bin/libwebpmux-1.dll     <--- only dll is there, no .dll.a in lib/
./i686-pc-mingw32.shared/bin/libwebpdemux-1.dll   <--- only dll is there, no .dll.a in lib/
./i686-pc-mingw32.shared/bin/libwebp-5.dll        <--- only dll is there, no .dll.a in lib/
./i686-pc-mingw32.shared/bin/libwebpdecoder-1.dll <--- only dll is there, no .dll.a in lib/
  1. In share mode, check the dll's are installed to the standard directory (usr/TARGET/bin), and not lib/.

    E.g. correct build:

timothy_gu@ubuntu-lenovo:~/mxe/usr$ find -name *libwebp*
./i686-pc-mingw32.shared/lib/libwebpdemux.la
./i686-pc-mingw32.shared/lib/libwebpmux.dll.a      <--- import lib
./i686-pc-mingw32.shared/lib/libwebpdecoder.la
./i686-pc-mingw32.shared/lib/libwebpdecoder.dll.a  <--- import lib
./i686-pc-mingw32.shared/lib/libwebpmux.la
./i686-pc-mingw32.shared/lib/libwebpdemux.dll.a    <--- import lib
./i686-pc-mingw32.shared/lib/pkgconfig/libwebp.pc
./i686-pc-mingw32.shared/lib/pkgconfig/libwebpdecoder.pc
./i686-pc-mingw32.shared/lib/pkgconfig/libwebpmux.pc
./i686-pc-mingw32.shared/lib/pkgconfig/libwebpdemux.pc
./i686-pc-mingw32.shared/lib/libwebp.dll.a         <--- import lib
./i686-pc-mingw32.shared/lib/libwebp.la
./i686-pc-mingw32.shared/installed/libwebp
./i686-pc-mingw32.shared/bin/libwebpmux-1.dll      <--- DLL in bin/
./i686-pc-mingw32.shared/bin/libwebpdemux-1.dll    <--- DLL in bin/
./i686-pc-mingw32.shared/bin/libwebp-5.dll         <--- DLL in bin/
./i686-pc-mingw32.shared/bin/libwebpdecoder-1.dll  <--- DLL in bin/

Wrong build:

timothy_gu@ubuntu-lenovo:~/mxe/usr$ find -name *libwebp*
./i686-pc-mingw32.shared/lib/libwebpdemux.la
./i686-pc-mingw32.shared/lib/libwebpmux.dll.a      <--- import lib
./i686-pc-mingw32.shared/lib/libwebpmux-1.dll      <--- DLL in lib/, WRONG
./i686-pc-mingw32.shared/lib/libwebpdecoder.la
./i686-pc-mingw32.shared/lib/libwebpdecoder.dll.a  <--- import lib
./i686-pc-mingw32.shared/lib/libwebpdecoder-1.dll  <--- DLL in lib/, WRONG
./i686-pc-mingw32.shared/lib/libwebpmux.la
./i686-pc-mingw32.shared/lib/libwebpdemux.dll.a    <--- import lib
./i686-pc-mingw32.shared/lib/libwebpdemux-1.dll    <--- DLL in lib/, WRONG
./i686-pc-mingw32.shared/lib/pkgconfig/libwebp.pc
./i686-pc-mingw32.shared/lib/pkgconfig/libwebpdecoder.pc
./i686-pc-mingw32.shared/lib/pkgconfig/libwebpmux.pc
./i686-pc-mingw32.shared/lib/pkgconfig/libwebpdemux.pc
./i686-pc-mingw32.shared/lib/libwebp.dll.a         <--- import lib
./i686-pc-mingw32.shared/lib/libwebp.la
./i686-pc-mingw32.shared/lib/libwebp-1.dll         <--- DLL in lib/, WRONG
./i686-pc-mingw32.shared/installed/libwebp