f



Question on GCC Java compiler

Hi,

I've always understood that gcj (the GCC Java compiler) was
something like a C or C++ compiler, only that it compiles
Java code  (and that is limited to non-graphical stuff).

In other words, that it would produce a standard, native-code
executable that behaves as the standard Java language dictates
that such program must behave.

Is this true?  I tried recently a sockets example (a quick
program that connects to port 13 and reads the datetime),
and get linking errors that sound pretty strange;  so, it
made me think that maybe gcj is basically the same as
the standard javac?  I.e., that it just compiles to
bytecode to be executed on a JVM that must be present
and running on the system?

Could someone enlighten me on this?  Or point me to some
documentation that helps me clarify this.

Thanks,

Carlos
--

0
Carlos
1/11/2004 4:01:11 AM
comp.os.linux.development.apps 5216 articles. 1 followers. Post Follow

6 Replies
293 Views

Similar Articles

[PageSpeed] 17

Carlos Moreno wrote:

> I've always understood that gcj (the GCC Java compiler) was
> something like a C or C++ compiler, only that it compiles
> Java code  (and that is limited to non-graphical stuff).

well, from the main page, it looks like it can do a lot of things:

"GCJ is a portable, optimizing, ahead-of-time compiler for the Java
Programming Language. It can compile:

  a.. Java source code directly to native machine code,
  b.. Java source code to Java bytecode (class files),
  c.. and Java bytecode to native machine code.

Compiled applications are linked with the GCJ runtime, libgcj, which
provides the core class libraries, a garbage collector, and a bytecode
interpreter. libgcj can dynamically load and interpret class files,
resulting in mixed compiled/interpreted applications."

http://gcc.gnu.org/java/

maybe if you are getting something funny it is in "Java source code to Java
bytecode" mode, or "mixed compiled/interpreted application" mode?

fwiw, my perhaps too old recollection is that the limit wasn't to
"non-graphical stuff" exactly ... but that the dividing line was code static
enough to be compiled to binary.  some java (and some class libraries) are
too dynamic for that.  foggy memoties, but i hope this helps.






0
Socks
1/11/2004 4:16:23 AM
Carlos Moreno <moreno_at_mochima_dot_com@x.xxx> writes:

> Could someone enlighten me on this?  Or point me to some
> documentation that helps me clarify this.

http://gcc.gnu.org/java/faq.html
0
Billy
1/11/2004 4:18:28 AM
Billy O'Connor wrote:
> Carlos Moreno <moreno_at_mochima_dot_com@x.xxx> writes:
> 
>>Could someone enlighten me on this?  Or point me to some
>>documentation that helps me clarify this.
> 
> http://gcc.gnu.org/java/faq.html

Hey, great!!  Well, I feel dumb now for having to ask
such a trivial question...  But hey, I got what I
deserved!  :-)

Thanks!  (thanks Socks also for the pointer and the
comments)

Carlos
--

0
Carlos
1/11/2004 6:27:03 AM
So, I could finally get the simple program to compile
(and more surprisingly, to work as expected! :-))

However, I do have a complaint...  Doesn't the Java
language specify that execution starts in the static
method named main in the class with the same name as
the source file??   I haven't done Java programming,
but from what I've seen and heard, I think this is
the case.

The only problem I was having was a "unresolved
reference to main" error -- and I solved it with
the switch --main=classname;  what I think is wrong
is that the compiler should have assumed what that
classname was (in my simple program, the "main"
class does have the same as the filename, and I
was expecting that to be sufficient for the
compiler to know what to do).

Carlos
--

0
Carlos
1/11/2004 10:16:59 PM
Carlos Moreno <moreno_at_mochima_dot_com@x.xxx> writes:

> So, I could finally get the simple program to compile
> (and more surprisingly, to work as expected! :-))
>
> However, I do have a complaint...  Doesn't the Java
> language specify that execution starts in the static
> method named main in the class with the same name as
> the source file??   I haven't done Java programming,
> but from what I've seen and heard, I think this is
> the case.

Not quite.  Execution starts with the main() method in the class named
on the command line when running "java".  Since gcj creates a single
executable from several classes, it needs to know in which of these to
look for main().

-- 
M�ns Rullg�rd
mru@kth.se
0
mru
1/11/2004 10:29:20 PM
M�ns Rullg�rd wrote:

> Not quite.  Execution starts with the main() method in the class named
> on the command line when running "java".  Since gcj creates a single
> executable from several classes, it needs to know in which of these to
> look for main().

Thanks for the clarification,

Carlos
--

0
Carlos
1/12/2004 5:11:07 PM
Reply: