Compiling Scala-generated bytecode

Marko Dimjašević marko@dimjasevic.net
Mon Oct 20 06:19:00 GMT 2014


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20141020/4c281d39/attachment.sig>


More information about the Java-patches mailing list