MinGW ld making DLLs into a very short file

112 views Asked by At

I want to link some .a files into a .dll file with MinGW ld, but it works bad: the .a files are big, like 0.98 MB, but when I do:

ld liba.a libb.a libc.a -shared -o final.dll

but it doesn't work well! I got an only 5 kb file final.dll. What should I do?

1

There are 1 answers

0
Keith Marshall On

You cannot link libraries like this: ld liba.a libb.a libc.a -shared -o final.dll; ld will never select any object module from any of them, because it never has any unresolved reference to satisfy. To achieve your objective, a possible workaround would be:

mkdir dlltmp
cd dlltmp
ar x ../liba.a
ar x ../libb.a
ar x ../libc.a
gcc -shared -o ../final.dll *.o

and, to clean up afterwards:

cd ..
rm -rf dlltmp

Do note the use of gcc rather than ld here; invoking ld directly is almost always a bad idea, (and if you used it as ld -o ../final.dll *.o, instead of the gcc command I've shown here, your link will surely fail due to unresolved references). Also note that I'm assuming that your gcc and ar are the MinGW tools, and that you have a unixy rm, (such as MSYS provides); if your tools are not these, then you may need mingw32-gcc, mingw32-ar, (or whatever else may be appropriate for you), and some alternative command to expunge the temporary directory.