[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: dynamic loading in static exe
From: |
Mumit Khan |
Subject: |
Re: dynamic loading in static exe |
Date: |
Mon, 27 Jan 2003 17:25:56 -0600 (CST) |
On Mon, 27 Jan 2003, Paul Kienzle wrote:
> Okay, it didn't work. The dll was easy to create:
>
> dlltool --export-all --output-exp libstdc++.exp --output-lib
> libstdc++.dll.a /usr/lib/libstdc++.a
> gcc -shared libstdc++.exp /usr/lib/libstdc++.a -o libstdc++.dll
> rm libstdc++.exp
That doesn't really do anything (``objdump -p libstdc++.dll'' will show
what I mean), you'll need to either use -Wl,--whole-archive, which will
cause you other problems, or extract all the objects from static libstdc++
and build a DLL from those.
$ mkdir tmp
$ (cd tmp; ar x /usr/lib/libstdc++.a)
$ gcc -shared -o libstdc++.dll tmp/*.o
$ cat testdll.cc
#include <iostream>
int main() { std::cout << "Hello world" << std::endl; }
$ gcc -o testdll testdll.cc libstdc++.dll
(or)
$ gcc -o testdll testdll.cc -L. -lstdc++
Chances are the that ./testdll will crash as some of the static objects
needed by libstdc++ won't be created correctly. You'd also need a "init"
routine for the DLL (typically called DllMain) that will initialize all
the static globals such as std::ios_base::ioinit. It's been too long since
I'd looked at these issues, so this is a good to stop before spreading
misinformation. There were people in Mingw list who have looked at it,
and they might help things along (Danny Smith has been there, done that,
etc).
Regards,
Mumit