PDA

View Full Version : java compiling problems



Arppa
December 7th, 2006, 05:36 PM
i've tried to compile hello world in java but i haven't succeeded yet.
when i try to compile for example. gcj Hello.java, compiler says:

/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

i just started java and i really don't know what is wrong with that.
i'd be very grateful if someone could help me :confused:

code:
public class Hello
{
public static void main(String[] args)
{
System.out.println("Hello World!!\n");
}
}

Tomosaur
December 7th, 2006, 05:52 PM
Can you post your code up here? Please use the CODE tags so it's easy to read.

Ramses de Norre
December 7th, 2006, 05:52 PM
You should post the code you are trying to compile, only that error message doesn't give much info..

Desi-Tek.com
December 7th, 2006, 06:24 PM
@Arppa there is nothing wrong in ur code just save it as Hello.java
and compile it using this command

javac Hello.java

and run it using

java Hello
btw why u r using gcj? use the sun's jdk it is free it is fast it is good :)

Ramses de Norre
December 7th, 2006, 06:27 PM
You'll have to install sun's java first then:

sudo aptitude install sun-java5-bin sun-java5-jdk
Make sure to enable multiverse to be able to install these packages.

Arppa
December 7th, 2006, 06:30 PM
thank you for helping me :)
i've used suns jdk on windows and it's terribly slow :(
takes about 20 secs to compile that code

Tomosaur
December 7th, 2006, 06:37 PM
thank you for helping me :)
i've used suns jdk on windows and it's terribly slow :(
takes about 20 secs to compile that code

That's probably more to do with windows than it is to do with the software :P

Sun's JDK is probably the best option - gcj is incompatible and incomplete. It causes more problems than it solves in my experience.

ruhar
December 7th, 2006, 06:45 PM
If you are having performance problems with the jdk to compile a simple HelloWorld class, it has probably got more to do with the operating system/utilities than the jdk. I have to write my java code on Windows at work, and I can't do any work unless the virus scan is completely turned off because it is configured to deep scan all java processes. This causes all java processes to run extremely slow (1 minute to launch eclipse) That may be why your windows compilations are so slow.

Ramses de Norre
December 7th, 2006, 06:57 PM
thank you for helping me :)
i've used suns jdk on windows and it's terribly slow :(
takes about 20 secs to compile that code

Another reason to use linux ;)

Arppa
December 7th, 2006, 07:04 PM
intresting becouse everything else runs smoothly, but when i try to compile everything freeze for 30 secs :S

kaamos
December 7th, 2006, 07:04 PM
i've tried to compile hello world in java but i haven't succeeded yet.
when i try to compile for example. gcj Hello.java, compiler says:

/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

i just started java and i really don't know what is wrong with that.
i'd be very grateful if someone could help me :confused:

You are trying to compile your program into a linux binary. :) Use
gcj -C Hello.java
to create java bytecode (.class-files).

Arppa
December 7th, 2006, 08:58 PM
problem solved. thank you all :)

vze4p6c2
December 8th, 2006, 03:08 AM
I suggest you use Windows for that. They have less problems like that. And since you won't be doing kernel programming in java, you probably will encounter more problems in linux. They have perfect NetBeans (http://www.netbeans.org/) and BlueJ (http://www.bluej.org/) compiler for Java which are very stable, and have lots of documentation on functions as well as support (especially NetBeans).

From my point of view, linux supports very little of java, comparing to c.

Vlad

shining
December 8th, 2006, 12:42 PM
If you have the java-gcj-compat package, you can compile java programs with gcj exactly the same than with sun java.
Just do:


javac Hello.java
java Hello


For choosing between gnu java and sun java (in case you have both java-gcj-compat and sun-java5-jdk installed), use update-java-alternatives.
But it shouldn't make any difference for simple programs.

Circus-Killer
December 8th, 2006, 12:48 PM
i agree with the other posts stating to rather use sun's java rather than gcj. as they said, sun's version offers greater compatibility. personally, i would never develop anything in java without using sun's version. just my opinion, but it also looks im not alone on this opinion.

Ramses de Norre
December 8th, 2006, 01:01 PM
I suggest you use Windows for that. They have less problems like that. And since you won't be doing kernel programming in java, you probably will encounter more problems in linux. They have perfect NetBeans (http://www.netbeans.org/) and BlueJ (http://www.bluej.org/) compiler for Java which are very stable, and have lots of documentation on functions as well as support (especially NetBeans).

From my point of view, linux supports very little of java, comparing to c.

Vlad

Kernel programming in java? How would you do that?

And I program quiet a lot in java on Linux and know people who develop java programs on Linux for living and it certainly works at least as well as windows.
I'd never even think about going to windows for developing..
And the java API is available online and IDE's as eclipse give you at least as much information about available classes/methods/... as any other windows IDE.