Static build failing to load classes
David Daney
ddaney@avtrex.com
Wed Nov 16 23:07:00 GMT 2005
Scott Gilbertson wrote:
> I'm trying to do a static build with today's gcj code. With a trivial java
> program,
> it crashes, apparently unable to load a class I'm reasonably sure is
> included
> in the binary. Is this a known problem?
>
Welcome to the world of static linking.
In the startup code (generated by the magic --main=) we add this:
extern int _ZN3gnu4java6locale8Calendar6class$E;
int *dummy1 = &_ZN3gnu4java6locale8Calendar6class$E;
extern int _ZN3gnu4java6locale17LocaleInformation6class$E;
int *dummy2 = &_ZN3gnu4java6locale17LocaleInformation6class$E;
extern int _ZN3gnu3gcj7convert12Output_ASCII6class$E;
int *dummy3 = &_ZN3gnu3gcj7convert12Output_ASCII6class$E;
extern int _ZN3gnu3gcj7convert28Output_UnicodeLittleUnmarked6class$E;
int *dummy4 = &_ZN3gnu3gcj7convert28Output_UnicodeLittleUnmarked6class$E;
extern int _ZN3gnu3gcj7convert11Output_UTF86class$E;
int *dummy5 = &_ZN3gnu3gcj7convert11Output_UTF86class$E;
You can get the startup code by using -save-temps and then modify the
startup code file and compile it with gcc and re-link without the --main=...
I think an alternatative would be to do this somewhere:
void dummy()
{
Object o = new gnu.java.locale.LocaleInformation();
}
Which would force the missing class to be loaded. You will probably
have to iterate to get them all.
As Pinski said in the other reply, you could use --whole-archive, but
that makes the resulting executable much larger. If you use
--whole-archive you might as well just use the shared libgcj object.
David Daney.
More information about the Java
mailing list