This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Static build failing to load classes
- From: David Daney <ddaney at avtrex dot com>
- To: Scott Gilbertson <scottg at mantatest dot com>
- Cc: java at gcc dot gnu dot org
- Date: Wed, 16 Nov 2005 15:07:08 -0800
- Subject: Re: Static build failing to load classes
- References: <309a01c5eb00$fc6ff450$3c16a8c0@mantatest.com>
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.