Re: Compiling java (gcj, jikes, kaffe...)
On Sat, Jan 27, 2001 at 08:43:04PM +0100, Andreas Hetzmannseder wrote:
| Dear debian-users,
|
| This is really stupid, but I don't know any further.
| Every time I try to compile some java source code - actually the HelloWorld
| example from the Debian Java FAQ - I get error messages:
|
| with gcj:
| /usr/lib/crt1.o: In function `_start':
| /usr/lib/crt1.o(.text+0x18): undefined reference to `main'
| collect2: ld returned 1 exit status
gcj outputs C++ object files from the Java source. Then (unless you
gave it the -c option) it links it to form an ELF binary (just like
C/C++). The problem is the linker can't find main.
int main( int argc , char** argv )
{
/* ... */
return 0 ;
}
The solution is to tell gjc where main is:
gcj --main=MyJavaClassDefiningMain *.java
gcj will then run a script (installed with it) to spit out some C/C++
code with the appropriate main() function that will call the main you
defined in your Java class. If you give gcj the -c option it will
stop when it has produced C++ object files (.o). You can then link
them at the end.
gcj also has a -C option will tells it to output Java bytecodes
(.class) instead. These will then need some JVM (jre, kaffe, etc) to
run.
|
| with jikes:
| Found 2 system errors:
|
| *** Error: Could not find package named
| /usr/share/java/repository/java/util
|
| *** Error: Could not find package named
| /usr/share/java/repository/java/lang
|
The packages java.util and java.lang can't be found by the compiler.
I haven't used jikes before so I can't be more specific. Maybe a
CLASSPATH problem?
| with kaffe's kjc:
| java.lang.NoClassDefFoundError: at/dms/kjc/Main
| at java.lang.Throwable.<init>(Throwable.java:38)
| at java.lang.Error.<init>(Error.java:21)
| at java.lang.LinkageError.<init>(LinkageError.java:21)
| at java.lang.NoClassDefFoundError.<init>(NoClassDefFoundError.java:21)
|
I guess that kjc is a shell script that tries to run a java program.
Apparently the main() function here is in the class "Main" in the
package "at.dms.kjc" and the class can't be found. This is definitely
a CLASSPATH problem.
When I tried out kaffe, it had the commands "javac" for compiling and
"java" for executing bytecodes. I think they were really just
symlinks to the kaffe commands. Perhaps trying these commands will
help?
| BTW: Running ready programs with kaffe works just fine...
|
| I put the following entry into my ~/.profile:
| export CLASSPATH=/usr/share/kaffe
I would recommend against this. At my present job I am using a Win2k
box (with cygwin of course) and Sun's jdk. I found it is much better
to make a whole collection of shell scripts that execute the proper
JVM (I have 1.1.8, 1.2.2, and 1.3 installed) with the proper classpath
stuff on the command line. For Sun's jdk, the "-classpath <system
specific path list>" option set the classpath. For jdk1.1.8
classes.zip must be listed in the option, for jdk1.2+ rt.jar is found
automagically (but tools.jar must be included to use ant -- a make
replacement for java devel).
The funny thing is the classpath must be in DOS/Windows format (with
d:, etc and semicolons as the separator) but I use cygwin's bash for
my shell. I always have to put the path list in quotes and escape all
the backslashes. It's quite a pain. Why did MS have to use the
escape character for the directory separator? POSIX paths are much
easier to deal with IMO.
|
| Could someone please tell me what is wrong or missing?
| Thanks in advance,
| Andreas.
|
HTH,
-D
Reply to: