Does gcj work?

Jung-uk Kim jkim at FreeBSD.org
Thu Feb 28 00:32:54 UTC 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2013-02-27 17:45:54 -0500, Guy Helmer wrote:
> I have been trying to get HelloWorld.java to work when compiled
> with gcj47 on both i386 and amd64. Seems like it should work. This
> code:
> 
> public class HelloWorld { public static void main(String[] args) { 
> System.out.println("Hello, World!"); } }
> 
> compiled thus: redwater:~ (515) gcj47 --main=HelloWorld -o
> HelloWorld HelloWorld.java
> 
> always croaks: redwater:~ (516) ./HelloWorld Abort (core dumped)
> 
> redwater:~ (517) gdb751 HelloWorld HelloWorld.core ... (gdb) where 
> #0  0x2a4b573b in thr_kill () from /lib/libc.so.7 #1  0x2a42f986 in
> ?? () from /lib/libthr.so.3 #2  0x2a43005b in raise () from
> /lib/libthr.so.3 #3  0x2a55e04a in abort () from /lib/libc.so.7 #4
> 0x28b4b08f in _Jv_Throw (value=0xbfbfd894) at
> ../.././../gcc-4.7-20130119/libjava/exception.cc:128 #5  0x28b892a8
> in java::lang::Class::forName (className=0x844b9c0, initialize=1
> '\001', loader=0x0) at
> ../.././../gcc-4.7-20130119/libjava/java/lang/natClass.cc:108 #6
> 0x28b9ac67 in java.lang.Class.forName(java.lang.String, 
> java.lang.Class)java.lang.Class (className=@844b9c0,
> caller=@29fb6c80) at
> ../.././../gcc-4.7-20130119/libjava/java/lang/Class.java:133 #7
> 0x28fd457e in java.net.URLClassLoader.addURLImpl(java.net.URL)void
> ( this=this at entry=@845afa0, newUrl=newUrl at entry=@8449c80) at 
> /usr/ports/lang/gcc47/work/gcc-4.7-20130119/libjava/classpath/java/net/URLClassLoader.java:332
>
> 
#8  0x28fd4c83 in java.net.URLClassLoader.addURL(java.net.URL)void
> (this=@845afa0, newUrl=@8449c80) at 
> /usr/ports/lang/gcc47/work/gcc-4.7-20130119/libjava/classpath/java/net/URLClassLoader.java:281
>
> 
#9  0x28ba83e4 in gnu.gcj.runtime.SystemClassLoader.init()void
> (this=@845afa0) at 
> /usr/ports/lang/gcc47/work/gcc-4.7-20130119/libjava/gnu/gcj/runtime/SystemClassLoader.java:89
>
> 
- ---Type <return> to continue, or q <return> to quit---
> #10 0x28babed5 in
> gnu.gcj.runtime.ExtensionClassLoader.initialize()void () at 
> /usr/ports/lang/gcc47/work/gcc-4.7-20130119/libjava/gnu/gcj/runtime/ExtensionClassLoader.java:33
>
> 
#11 0x28b3f600 in _Jv_CreateJavaVM (vm_args=vm_args at entry=0x0)
> at ../.././../gcc-4.7-20130119/libjava/prims.cc:1670 #12 0x28b3fb38
> in _Jv_RunMain (vm_args=0x0, klass=klass at entry=0x8049240
> <HelloWorld::class$>, name=name at entry=0x0, argc=argc at entry=1,
> argv=argv at entry=0xbfbfdb98, is_jar=is_jar at entry =false) at
> ../.././../gcc-4.7-20130119/libjava/prims.cc:1720 #13 0x28b3fea2 in
> _Jv_RunMain (klass=klass at entry=0x8049240 <HelloWorld::class$>, 
> name=name at entry=0x0, argc=argc at entry=1,
> argv=argv at entry=0xbfbfdb98, is_jar=is_jar at entry=false) at 
> ../.././../gcc-4.7-20130119/libjava/prims.cc:1815 #14 0x28b3ff3b in
> JvRunMain (klass=0x8049240 <HelloWorld::class$>, argc=1, 
> argv=0xbfbfdb98) at
> ../.././../gcc-4.7-20130119/libjava/prims.cc:1821 #15 0x08048ad9 in
> main ()
> 
> Any ideas?

It works.  You just missed a very important option:

% gcj48 --main=HelloWorld -o HelloWorld HelloWorld.java
Abort (core dumped)
% ./HelloWorld
% gcj48 --main=HelloWorld -Wl,-rpath=/usr/local/lib/gcc48 -o
HelloWorld HelloWorld.java
% ./HelloWorld
Hello, World!

As you can see, you had to add "-Wl,-rpath=/usr/local/lib/gcc48" (or
"-Wl,-rpath=/usr/local/lib/gcc47" in your case).

Jung-uk Kim
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (FreeBSD)

iQEcBAEBAgAGBQJRLqU9AAoJECXpabHZMqHOnNoH/ih5dkcrP5EHdeKuTA03EUC7
QbyvcWIVGFMIlceUTJfdypaO2QaqeN8w83PX+BLBgkWH+g/8yXnkfIc1J/uMd1zT
e7UO5pozWH/KDI+tWDjz4T7M/wM61CgPsgNaOgYXx85kE4m8NakxF+DBizCMfid5
5FYTfX+Fq5xpD0Nq5iJeweVjbyqHSJVyHcED4+RXxOoKXjWPlfv9w48r0mpJrIY4
lQCcmZdan1v2WecDHaYvOIJVxGqdPIfx5oZymz61EV9crEZg5ewvSW70gQOkVUc7
AepQoTIb9WnDPZoWuljCBLGQzccERRlpD/5qaLK0SWQ5dG4ajg53aVM4ociTpwk=
=16+x
-----END PGP SIGNATURE-----


More information about the freebsd-java mailing list