Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Learning C, getting a wierd erro when compiling with gcc

  1. #1
    Join Date
    Jun 2006
    Location
    Guelph (the royal city)
    Beans
    128
    Distro
    Ubuntu 7.04 Feisty Fawn

    Learning C, getting a wierd erro when compiling with gcc

    I'm just learning C. I made a simple prog called test.C, here it is:

    #include <stdio.h>
    int main(int argc, char** argv)
    {
    printf("Hello test\n");
    return 0;
    }

    this is the error I get

    bman@wherewulf:~$ gcc test.C
    /tmp/ccKH5JHY.o.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
    collect2: ld returned 1 exit status

    my friend is a programmer, and says he has no clue about this. Any help would be appreciated for this future 733t programmer (yes, I'm a big geek!)

  2. #2
    Join Date
    May 2005
    Location
    Helsinki, Finland
    Beans
    Hidden!

    Re: Learning C, getting a wierd erro when compiling with gcc

    Well, that error usually means you tried to link C++ code with gcc (a C compiler). I'm a little baffled why that would happen with your code...

    Have you installed the build-essential package?

  3. #3
    Join Date
    Jun 2006
    Location
    Guelph (the royal city)
    Beans
    128
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: Learning C, getting a wierd erro when compiling with gcc

    yes I have

  4. #4
    Join Date
    Aug 2006
    Location
    Nashville, TN
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Learning C, getting a wierd erro when compiling with gcc

    just out of curiosity... why the capital 'C' in the source code file extension?

    i tried it out and this is your problem... you named the source file 'test.C' and not 'test.c' - emphasis being on the capital 'C'... if you simply rename the file to 'test.c' with a lower-case c your problem will be resolved...

    Code:
    mv test.C test.c
    now your code will compile...

  5. #5
    Join Date
    Sep 2006
    Beans
    Hidden!

    Re: Learning C, getting a wierd erro when compiling with gcc

    xboxbman,

    Just to elaborate on the previous post, older C++ programs were suffixed with .C as opposed to .c. I'm guessing that's the cause of the __gxx_personality_v0 error (gxx meaning g++).

  6. #6
    Join Date
    Aug 2006
    Location
    Nashville, TN
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Learning C, getting a wierd erro when compiling with gcc

    and that explains why this error occurs...

    i guess the capital 'C' extension for C++ files was before my time... i've always named my C++ with the '.cpp' extension...

  7. #7
    Join Date
    Jun 2006
    Location
    Guelph (the royal city)
    Beans
    128
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: Learning C, getting a wierd erro when compiling with gcc

    no more error, but nothing happens. The learning C book I have is assuming you're working on a windows machine, so it have no info on running these in linux. I type "gcc test.c", I hear the hardrive spin for a second, then nothing. I get the same effect just hitting enter. sorry to hassle you guys with these low level, questions, but I gotta start somewhere.

  8. #8
    Join Date
    Aug 2006
    Location
    Nashville, TN
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Learning C, getting a wierd erro when compiling with gcc

    that means it compiled with no problems...
    in that same directory you should now have a file called 'a.out'....
    to execute the file issue this command at the terminal:
    Code:
    ./a.out
    the most important part of that being the './'
    don't forget it... that tells the shell where the file is located...

    to be clear this is what you need to do assuming you are at the directory containing your source code

    Code:
    gcc test.c
    ./a.out
    let us know how it goes

  9. #9
    Join Date
    Jun 2006
    Location
    Guelph (the royal city)
    Beans
    128
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: Learning C, getting a wierd erro when compiling with gcc

    hurray! my first program, lame as it is, works. Next stop, world domination! Mwahahahaha!!! But seriously, thanks for the help. I know it was silly little questions, but one thing I've learned is that a moment of stupidity is better than a lifetime of ignorance.

    Thanks again jhaitas

  10. #10
    Join Date
    Aug 2006
    Location
    Nashville, TN
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Learning C, getting a wierd erro when compiling with gcc

    i remember when i was in the same place as you...

    let me know if you have any more issues...

    one side note... if you want to give your executable a meaningful name - use the '-o' argument in the gcc command:

    Code:
    gcc test.c -o test.out
    ./test.out
    see how that works for you...
    fyi: one of the best resources are the manpages...
    to read up on gcc you can issue the command:
    Code:
    man gcc
    you will get a lot of useful information there... furthermore the man command can be used for other commands like 'ls' or 'lsof'... any command you use at the terminal should have associated manpages... ('man' being short for 'manual')

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

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