Compiling Scala-generated bytecode

Marko Dimjašević <[email protected]> Sun, 19 Oct 2014 23:19:11 -0700
Newsgroups gmane.comp.gcc.java.patches
Message-ID <1413785951.4798.12.camel@neelix>
Hi all,

I've been trying to compile Scala-generated bytecode to native machine
code, but without luck so far.

Here's the program I want to compile:

object HelloWorld {
	def main(args: Array[String]) {
	  println("Hello, Scala World!")
	}
}

I can easily compile it to bytecode:

$ scalac HelloWorld.scala

This generates two files: HelloWorld.class and HelloWorld$.class.

Then I'd like to compile these class files to the machine code. Here is
my attempt:

$ gcj --classpath=/usr/share/java/scala-library-2.9.2.jar:. *.class
--main=HelloWorld 
/tmp/ccFGxiOv.o: In function `void HelloWorld
$::main(JArray<java::lang::String*>*)':
HelloWorld$.class:(.text+0x39): undefined reference to `scala::Predef
$::class$'
HelloWorld$.class:(.text+0x4a): undefined reference to `scala::Predef
$::MODULE$'
HelloWorld$.class:(.text+0x73): undefined reference to `void
scala::Predef$::println(java::lang::Object*)'
/tmp/ccFGxiOv.o:(.data+0xf8): undefined reference to
`scala::ScalaObject::class$'
collect2: error: ld returned 1 exit status


All of these undefined reference classes are in scala-library-2.9.2.jar.
What am I missing?

Here are details on GCJ that I have:

$ gcj -v
Using built-in specs.
Reading specs from /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcj.spec
rename spec startfile to startfileorig
rename spec lib to liborig
COLLECT_GCC=gcj
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-3'
--with-bugurl=file:///usr/share/doc/gcj-4.7/README.Bugs
--enable-languages=c,c++,java --prefix=/usr --program-suffix=-4.7
--enable-shared --enable-linker-build-id --with-system-zlib
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib
--enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-time=yes --enable-gnu-unique-object
--disable-libmudflap --enable-plugin --disable-browser-plugin
--enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.7/jre --enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.7
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.7
--with-arch-directory=amd64
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-arch-32=i586
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.2 (Debian 4.7.2-3)


-- 
Kind regards,
Marko Dimjašević
http://dimjasevic.net/marko
signature.asc (application/pgp-signature, 836 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iQIcBAABAgAGBQJURKlfAAoJEGjtezy5N0tH+AgP/jVPEBxFjgdJmFtLudp6/MTY
N6fOOfhf093iIpxkGse2EFTp7VrAPKFta6mPnMqysgXLjLYlnX63Fcrrx6+EXtwX
gSBIfS48KlvMQSzimxmJnon7Wkh3Fsf+ErPHCJAhT0vMczqKCGzRh5OIx2UE224Y
KEGzoGu2mPyRJ/AYBDpkeiymz82vDOHDDOhayv/8ro5VamPKRSVko7E3UC8y+lsm
YXr0tMyUnEK8ur9sH5ilJiE7DbNCgYwKJUcD/DKof47xe79P22NrGQx+3c8MBbw5
y2BPNeLIMNgePWCwVFlliwGLgsOFk/djfy6S2hhbGkyt6JlJ2pJqAHsTPBMJ6Wld
bd9l0Sb93vciGQtg2Md1YdQYHJF/h4fFDhLVUPLt6CSCHi5Omm4cZxwGwg+8PLzW
sBZWEKpMFJaqzZMCiiGpi/0pPAzGahyi0VML41MrBltEChgJKemN1jGRwlE5kBuI
NeLRJ4IQgzv2qbmo0iq1bt+BCJwgnO69h2wZvBrNkvmvGyTwqGWcEUOSVse2+XCy
ZY/71p08kmWjuCiPOf5r+dpvwbqd0LhoFwNLSYuA/Uxd+5WefkUTxeQ67Hhty9mv
/bNlP9/xVKIrjUhIrx+LKdg1Rn8sJecydhcdG2DuiNkDDi5KmrYkUJ6a+32t9reJ
6h6V9OstvfFOmxQ2tawA
=flcN
-----END PGP SIGNATURE-----