mingw-cross-env-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Mingw-cross-env-list] MXE: How to build a self-sufficient DLL that


From: Matthias Geier
Subject: Re: [Mingw-cross-env-list] MXE: How to build a self-sufficient DLL that statically includes other libraries?
Date: Fri, 27 Mar 2015 09:59:07 +0100

Hi all.

In case somebody is interested: I found a solution!

After a lot of experimenting and searching the web, I finally found
out that it's actually quite simple.

Static libraries can be converted to DLLs with gcc (which in turn
calls ld) using the -shared flag. Without this flag, gcc would try to
make an .exe file, which wouldn't work because there is no main
function (and besides, I don't want an .exe file anyway).

The essential part, which took me quite a while to find out, is to use
the option -Wl,--whole-archive; otherwise the generated DLL will be
essentially empty!
The linker only includes the symbols which are actually used, except
the --whole-archive option is passed, then it blindly includes
everything (which is what I want).

These are the exact commands which are working for me (on Debian
Linux, by the way):

JOBS=8
git clone https://github.com/mxe/mxe.git
export PATH=$(pwd)"/mxe/usr/bin:$PATH"
for TARGET in x86_64-w64-mingw32.static i686-w64-mingw32.static
do
    make -C mxe libsndfile -j$JOBS JOBS=$JOBS MXE_TARGETS=$TARGET
    $TARGET-gcc -O2 -shared -o libsndfile-$TARGET.dll
-Wl,--whole-archive -lsndfile -Wl,--no-whole-archive -lvorbis
-lvorbisenc -logg -lFLAC
    $TARGET-strip libsndfile-$TARGET.dll
done

This creates stripped DLLs for 64bit and 32bit, no changes to the MXE
sources needed.
Note that this works with the current master, it didn't work for the
stable branch (but this could probably be fixed).
I only tested the 64bit DLL, I hope the other DLL also works ...

If anybody knows a better way to do this, please tell!

Thanks again to Nikos for getting me started!

cheers,
Matthias

On Wed, Mar 25, 2015 at 8:02 PM, Matthias Geier
<address@hidden> wrote:
> Hello again!
>
> I did some more digging regarding the warning message I got:
>
> *** Warning: This system can not link to static lib archive
> [...]/usr/x86_64-w64-mingw32/lib/libvorbis.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.
>
> ... and I found this very interesting thread:
> http://ehc.ac/p/mingw/mailman/message/20144165/
>
> According to this, the culprit may be libtool, because it just doesn't
> support linking a static library into a dynamic one.
> But there may be 2 work-arounds:
>
> 1) pass some linker flags like -Wl,/path/to/libfoo.a or -Wl,-lfoo.a
> 2) use dlltool
>
> Both sound promising, but I don't know the exact usage of any of them.
>
> Can somebody help me with this?
>
> Here's what I want to do, for those who didn't read my previous messages:
> I would like to create a DLL of libsndfile that statically includes
> all its dependencies so I can use it from within Python.
>
> I've successfully compiled everything as static and everything as
> shared, but I don't know how to take the static libs and forge them
> together into a single shared DLL.
>
> cheers,
> Matthias



reply via email to

[Prev in Thread] Current Thread [Next in Thread]