|
||||||
| Forums FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| ARCHIVES - Programming & Scripting A place to discuss website design, programming, shell scripts, etc |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi,
I am trying to compile the old classic Hello World C program and I am getting this error: /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/bin/ld: cannot find -lc collect2: ld returned 1 exit status Here's the source: Code:
#include <stdio.h>
#include <stdlib.h>
void main() {
printf ("\nhello world\n");
}
|
|
|||
|
First of all, make sure your source file has a .c extension. Next, compile your code with this command: "gcc -o sourcefile sourcefile.c". The -o sourcefile part makes an executable file called sourcefile. Next, type "./sourcefile" to execute your program. It ran on my machine, so your code is correct. I think you compiled it incorrectly. You may get a compiler warning such as "warning: return type of ‘main’ is not ‘int’", but this can be ignored.
|
|
|||
|
Hi,
Thanks for your reply. I tried it with the extra parameters but I still get the errors. It looks like there is a library missing or something... Code:
jlawlor@apollo:~/Documents/scripts> gcc -o hello hello.c hello.c: In function ‘main’: hello.c:4: warning: return type of ‘main’ is not ‘int’ hello.c:8:2: warning: no newline at end of file /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/bin/ld: cannot find -lc collect2: ld returned 1 exit status jlawlor@apollo:~/Documents/scripts> |
|
|||
|
hi
the problem is not about your code it's correnct but the compiler told you that you don't have the needed libs which enable your programme to be executable when you use printf by include it's implementation there still some thing it's the binary lib which open stream between your programme and the screen and it's called glibc libs so check that you have these libs in ur system in any lib directory which execution permission for any user such /usr/lib/ you can search using some thing like this find / |grep glibc try it |
|
|||
|
C likes for the main function to return an integer between 0 and 255 to the operating system. C++ popularized "void main()".
So change "void main" to "int main". At the end of the main function, add a line, return 0; The warning "hello.c:8:2: warning: no newline at end of file" seems strange. Maybe in your code, add one more blank line after the closing "}". Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
********printf ("\nhello world\n");
********return 0;
}
|
|
|||
|
Quote:
Change the source to #include<stdio.h> main() { printf ("\nhello world\n"); } Give it a name say hello.c compile it with cc hello.c I think it will work.
|
|
|||
|
No, it looks like a problem between the 32 & 64 bit versions of libc installed. Are you running opensuse 64 bit? Did you install the correct libraries for your development? The error has nothing to do with your code. The libc it is looking for is missing. Maybe you are running the 32bit version of gcc?
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|