LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   "Hello, World!" compiling problems (https://www.linuxquestions.org/questions/programming-9/hello-world-compiling-problems-404085/)

BurningBreeze 01-16-2006 12:22 PM

"Hello, World!" compiling problems
 
I have compiled a "hello, world" program before in Linux. I cant remember the command line and now i am having problems, i'm using slackware 10.1 and knoppix 3.8 and in both when i try am compile:

/* ------ hello.C ------- */
#include<stdio.h>
int main(void) {
printf("Hello, world!\n\n");
return 0;
}
/* ------- End --------- */

under the command:
gcc hello.C -o hello

i get the following error
/tmp/ccAp71uc.o(.eh_frame+0x11): undefined reference to'__gxx_personality_v0'
collect2: ld returned 1 exit status

Any suggestions?
Thank you, BurningBreeze.

jtshaw 01-16-2006 12:38 PM

The problem is the uppercase C in the file extension.

gcc automatically assumes that .C, .cpp, .cxx, .cc, ect. are C++ files. If you attempt to compile a C++ file using gcc without linking to -lstdc++ it will not work.

Either of these will work
gcc -lstdc++ -o test test.C
g++ -o test test.C
or rename test.C to test.c and use
gcc -o test test.c

Also, in the future please use the code blocks.

Code:

#include<stdio.h>

int main(void) {
    printf("Hello, world!\n\n");
    return 0;
}


dombrowsky 01-16-2006 12:39 PM

try running it with a lowercase 'c'. I think that gcc automatically interprets the *.C as c plus plus, and your c++ libs might be broken (it happens). But if "gcc hello.c" fails, then your compiler is broken.

BurningBreeze 01-16-2006 12:48 PM

No errors came up after i renamed the file. but when i type 'hello' at the Konsole it doesen't run. so i typed 'gdb hello' and then in gdb 'run' and it ran. why wont the Konsole run it?

jtshaw 01-16-2006 01:32 PM

Try ". hello" or "./hello". Most likely the current directory just isn't in your system path.

BurningBreeze 01-16-2006 02:48 PM

'./hello' worked! thanks dude! I obviously worked with a different distro when i was previously compiling in linux.

Mara 01-16-2006 04:04 PM

Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.


All times are GMT -5. The time now is 05:53 PM.