Results 1 to 6 of 6
  1. #1
    phil128 is offline Member
    Join Date
    Sep 2008
    Posts
    40
    Rep Power
    0

    Default Hello World in linux returns undefined reference to `main' collect2: ld return

    Hello. I'm getting really stressed out about the fact tht i cannot compile the most simply program of all! I keep on getting errors, And all i've done is copy and paste source code, jus so i know tht my java complier is working!

    -----SOURCE-----

    public class HelloWorld {

    public static void main (String[] args) {
    System.out.println("Hello, world!\n");
    }

    }

    ----ERROR----

    javac '/home/photek/Desktop/HelloWorld.java' /usr/lib/gcc/i586-suse-linux/4.3/../../../crt1.o: In function `_start':
    (.text+0x18): undefined reference to `main'
    collect2: ld returned 1 exit status
    .
    Could some1 please help me :-(. i start my uni course next week and i want to get things atlease working.

    Honestly people your help will mean the world to me.

    Thanks

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    What version of the JDK are you using? I don't recognize the error message from the javac command.

    What is the path/file that follows the source file on the commandine you show?
    /usr/lib/gcc/i586-suse-linux/4.3/../../../crt1.o

  3. #3
    phil128 is offline Member
    Join Date
    Sep 2008
    Posts
    40
    Rep Power
    0

    Default

    I've sorted it :-D. I ad to pass arguments to main to get it work :-D via the terminal.

    Thanks for the reply tho!

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    I guess I was confused. I thought you were having problems compiling. Passing args to main sounds like executing.
    But HelloWorld doesn't take args???

  5. #5
    xxqtony is offline Member
    Join Date
    Sep 2008
    Posts
    1
    Rep Power
    0

    Default

    Quote Originally Posted by phil128 View Post
    I've sorted it :-D. I ad to pass arguments to main to get it work :-D via the terminal.

    Thanks for the reply tho!
    How did you solve it? Thanks!

  6. #6
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Default

    Quote Originally Posted by phil128 View Post
    ----ERROR----

    javac '/home/photek/Desktop/HelloWorld.java' /usr/lib/gcc/i586-suse-linux/4.3/../../../crt1.o: In function `_start':
    (.text+0x18): undefined reference to `main'
    collect2: ld returned 1 exit status
    I had the exact same problem on OpenSuse 11.1.

    The gcc javac compiler doesn't work the same way as the sun javac compiler.

    Installed java-1_6_0-sun-devel - Java(TM) 6 SDK, Standard Edition and all my compile problems went away.

Similar Threads

  1. Replies: 9
    Last Post: 01-23-2014, 07:17 PM
  2. Replies: 6
    Last Post: 04-08-2009, 04:05 AM
  3. Replies: 2
    Last Post: 07-03-2008, 01:43 PM
  4. Getting the Object Reference Name
    By Deathmonger in forum New To Java
    Replies: 2
    Last Post: 03-12-2008, 02:51 PM
  5. Replies: 1
    Last Post: 08-06-2007, 09:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •