GCC not compiling C programs

I’m trying to learn C for an upcoming course; unfortunately, the GCC isn’t working correctly. I had this problem on another system and fixed it with build-utils, or something similar. However, that doesn’t do anything on OpenSuse 12.3. I write a simple hello world program and I get
“warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]” as a warning. What do I need to do to get the compiler working? Thanks.

On Tue, 21 May 2013 16:46:03 +0000, nautola wrote:

> I’m trying to learn C for an upcoming course; unfortunately, the GCC
> isn’t working correctly. I had this problem on another system and fixed
> it with build-utils, or something similar. However, that doesn’t do
> anything on OpenSuse 12.3. I write a simple hello world program and I
> get “warning: incompatible implicit declaration of built-in function
> ‘printf’ [enabled by default]” as a warning. What do I need to do to
> get the compiler working? Thanks.

Please define a specific set of steps you follow and what the exact
output (in CODE tags, use the “#” button in the advanced editor) that you
get, as well as your test code. The warning you posted may indicate a
problem with the code you wrote rather than the compiler.

Also make sure you’ve installed the development pattern.

Jim

Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

Like Jim says, it’s your code, not the compiler. AFAICS you’re declaring “printf” which should not be necessary since it’s built in, which means you have to use it without a declaration first.

I don’t know how it could be the code; I wrote it straight from The C Programming Language. I downloaded the pattern and ensured I had the gcc downloaded correctly. As far as I know, I have all the required files. I have also recently moved to OpenSuse, and I had these programs working on a Linux Mint machine.

#include <stdio.h>
   
   main()
   {
        printf("hello world
");
   }


On Wed, 22 May 2013 04:06:01 +0000, nautola wrote:

> As far as I know, I have all the required files.

What specifically did you install?

What is the full output when you try to compile? Again, in code tags,
please.

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

Make first sure you have the base development pattern installed


su -
zypper in -t pattern devel_basis

in reality I would go a step farther and use


su -
zypper in -t pattern devel_C_C++

at least this ensures that you are not missing essential parts which are
needed to do development.


PC: oS 12.3 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.10.2 | GTX 650 Ti
ThinkPad E320: oS 12.3 x86_64 | i3@2.30GHz | 8GB | KDE 4.10.3 | HD 3000
HannsBook: oS 12.3 x86_64 | SU4100@1.3GHz | 2GB | KDE 4.10.2 | GMA4500

Am 22.05.2013 07:03, schrieb Jim Henderson:
> What is the full output when you try to compile? Again, in code tags,
> please.

+1

To show how I tested the code (copied into check1.c)


martinh@ganymed:~/tmp> gcc -o check1 check1.c
martinh@ganymed:~/tmp> ./check1
hello world
martinh@ganymed:~/tmp> cat check1.c
#include <stdio.h>

main(){
printf("hello world
");
}
martinh@ganymed:~/tmp>


PC: oS 12.3 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.10.2 | GTX 650 Ti
ThinkPad E320: oS 12.3 x86_64 | i3@2.30GHz | 8GB | KDE 4.10.3 | HD 3000
HannsBook: oS 12.3 x86_64 | SU4100@1.3GHz | 2GB | KDE 4.10.2 | GMA4500

I have the developer patterns installed, but I double checked. I thought there might be something I didn’t know that I needed, so I went into yast and installed all the packages related to development in Python and C, that weren’t Gnome related, or causing conflicts. I also have a few other unrelated things like emacs, wine, yakuake, etc.

This is what I’m doing in the Terminal:

brandon@linux-4if6:~/Programming/General/Learning C/Chapter 1> gcc -o hello hello.c
hello.c: In function ‘main’:
hello.c:4:2: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
/usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../lib64/crt1.o: file not recognized: File truncated
collect2: error: ld returned 1 exit status

Am 22.05.2013 15:26, schrieb nautola:
> /usr/lib64/gcc/x86_64-suse-linux/4.7/…/…/…/…/lib64/crt1.o: file not recognized: File truncated
That looks as if your glibc-devel is corrupted!!!

Try to repair it with by a forced reinstall


su -
zypper in -f glibc-devel


PC: oS 12.3 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.10.2 | GTX 650 Ti
ThinkPad E320: oS 12.3 x86_64 | i3@2.30GHz | 8GB | KDE 4.10.3 | HD 3000
HannsBook: oS 12.3 x86_64 | SU4100@1.3GHz | 2GB | KDE 4.10.2 | GMA4500

Thank you so much, that did it! Wow, I feel silly now that it was such a simple fix.