public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Compiling Scala-generated bytecode
@ 2014-10-20  6:19 Marko Dimjašević
  2014-10-20  8:04 ` Andrew Haley
  0 siblings, 1 reply; 5+ messages in thread
From: Marko Dimjašević @ 2014-10-20  6:19 UTC (permalink / raw)
  To: java-patches

[-- Attachment #1: Type: text/plain, Size: 2626 bytes --]

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


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Compiling Scala-generated bytecode
  2014-10-20  6:19 Compiling Scala-generated bytecode Marko Dimjašević
@ 2014-10-20  8:04 ` Andrew Haley
  2014-10-20 13:50   ` Marko Dimjašević
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Haley @ 2014-10-20  8:04 UTC (permalink / raw)
  To: Marko Dimjašević, java-patches

On 20/10/14 07:19, Marko Dimjašević wrote:
> All of these undefined reference classes are in scala-library-2.9.2.jar. What am I missing?

You have to link with the Scala library, either directly or indirectly.
You will want to compile the library to a shared object.

Before explaining any more, do you have experience with shared
libraries in C and C++?

Andrew.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Compiling Scala-generated bytecode
  2014-10-20  8:04 ` Andrew Haley
@ 2014-10-20 13:50   ` Marko Dimjašević
  2014-10-20 21:46     ` Andrew Hughes
  0 siblings, 1 reply; 5+ messages in thread
From: Marko Dimjašević @ 2014-10-20 13:50 UTC (permalink / raw)
  To: Andrew Haley; +Cc: java-patches

[-- Attachment #1: Type: text/plain, Size: 1904 bytes --]

On Mon, 2014-10-20 at 09:04 +0100, Andrew Haley wrote:

> You have to link with the Scala library, either directly or indirectly.
> You will want to compile the library to a shared object.

That's what I thought.


> Before explaining any more, do you have experience with shared
> libraries in C and C++?

Just a tiny bit.

As far as my understanding goes, I'd first create a shared library with
something like this:

gcj -fPIC /usr/share/java/scala-library.jar -shared -o scala-library.so

and then when compiling a Scala program, I'd say:

gcj --classpath=.:/usr/share/java/scala-library.jar HelloWorld*.class
scala-library.so

But I haven't managed to create the shared library. When I attempt to
run the first command, I get something like:

scala/collection/immutable/StringLike.scala: In class
'scala.collection.immutable.StringLike$class':
scala/collection/immutable/StringLike.scala: In method
'scala.collection.immutable.StringLike
$class.replaceAllLiterally(scala.collection.immutable.StringLike,java.lang.String,java.lang.String)':
In file included from scala/collection/immutable/StringLike.scala:28:0,
                 from scala/collection/immutable/StringLike.scala:190,
                 from scala/collection/immutable/StringLike.scala:142,
		 ...
                 from scala/AnyVal.scala:7,
                 from <built-in>:3:
scala/collection/immutable/StringLike.scala:174:0: error: class
'java.util.regex.Pattern' has no method named 'quote' matching signature
'(Ljava/lang/String;)Ljava/lang/String;'
In file included from scala/collection/immutable/StringLike.scala:28:0,
                 from scala/collection/immutable/StringLike.scala:190,
                 from scala/collection/immutable/StringLike.scala:142,
		 ...


Can you please tell me how to get the shared library?


-- 
Regards,
Marko
http://dimjasevic.net/marko


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Compiling Scala-generated bytecode
  2014-10-20 13:50   ` Marko Dimjašević
@ 2014-10-20 21:46     ` Andrew Hughes
  2014-10-20 21:51       ` Marko Dimjašević
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Hughes @ 2014-10-20 21:46 UTC (permalink / raw)
  To: Marko Dimjašević; +Cc: Andrew Haley, java-patches



----- Original Message -----
> On Mon, 2014-10-20 at 09:04 +0100, Andrew Haley wrote:
> 
> > You have to link with the Scala library, either directly or indirectly.
> > You will want to compile the library to a shared object.
> 
> That's what I thought.
> 
> 
> > Before explaining any more, do you have experience with shared
> > libraries in C and C++?
> 
> Just a tiny bit.
> 
> As far as my understanding goes, I'd first create a shared library with
> something like this:
> 
> gcj -fPIC /usr/share/java/scala-library.jar -shared -o scala-library.so
> 
> and then when compiling a Scala program, I'd say:
> 
> gcj --classpath=.:/usr/share/java/scala-library.jar HelloWorld*.class
> scala-library.so
> 
> But I haven't managed to create the shared library. When I attempt to
> run the first command, I get something like:
> 
> scala/collection/immutable/StringLike.scala: In class
> 'scala.collection.immutable.StringLike$class':
> scala/collection/immutable/StringLike.scala: In method
> 'scala.collection.immutable.StringLike
> $class.replaceAllLiterally(scala.collection.immutable.StringLike,java.lang.String,java.lang.String)':
> In file included from scala/collection/immutable/StringLike.scala:28:0,
>                  from scala/collection/immutable/StringLike.scala:190,
>                  from scala/collection/immutable/StringLike.scala:142,
> 		 ...
>                  from scala/AnyVal.scala:7,
>                  from <built-in>:3:
> scala/collection/immutable/StringLike.scala:174:0: error: class
> 'java.util.regex.Pattern' has no method named 'quote' matching signature
> '(Ljava/lang/String;)Ljava/lang/String;'
> In file included from scala/collection/immutable/StringLike.scala:28:0,
>                  from scala/collection/immutable/StringLike.scala:190,
>                  from scala/collection/immutable/StringLike.scala:142,
> 		 ...
> 
> 
> Can you please tell me how to get the shared library?
> 

Which version of gcj are you using? This one looks to be too old to include
the Pattern.quote(String) method needed by Scala.

> 
> --
> Regards,
> Marko
> http://dimjasevic.net/marko
> 
> 

-- 
Andrew :)

Free Java Software Engineer
Red Hat, Inc. (http://www.redhat.com)

PGP Key: 248BDC07 (https://keys.indymedia.org/)
Fingerprint = EC5A 1F5E C0AD 1D15 8F1F  8F91 3B96 A578 248B DC07

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Compiling Scala-generated bytecode
  2014-10-20 21:46     ` Andrew Hughes
@ 2014-10-20 21:51       ` Marko Dimjašević
  0 siblings, 0 replies; 5+ messages in thread
From: Marko Dimjašević @ 2014-10-20 21:51 UTC (permalink / raw)
  To: Andrew Hughes; +Cc: Andrew Haley, java-patches

[-- Attachment #1: Type: text/plain, Size: 452 bytes --]

On Mon, 2014-10-20 at 17:46 -0400, Andrew Hughes wrote:

> Which version of gcj are you using? This one looks to be too old to include
> the Pattern.quote(String) method needed by Scala.

As I mentioned it in the first email:

gcc version 4.7.2 (Debian 4.7.2-3)


Ok, I'll try compiling GCC from sources myself with the same
configuration parameters as the build I have from Debian.


-- 
Regards,
Marko
http://dimjasevic.net/marko


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-10-20 21:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-20  6:19 Compiling Scala-generated bytecode Marko Dimjašević
2014-10-20  8:04 ` Andrew Haley
2014-10-20 13:50   ` Marko Dimjašević
2014-10-20 21:46     ` Andrew Hughes
2014-10-20 21:51       ` Marko Dimjašević

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).