[SOLVED]Help with setting up and using the GCC compiler

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
Sleven

[SOLVED]Help with setting up and using the GCC compiler

Post by Sleven »

I found a tutorial on learning C using the gcc compiler which is already install in lmde. I thought perfect.

The tutorial jumped right into the hello world program with out any instruction on the set up. As soon as I tried to compile I got the following error:

hello.c:1:20: error: stdio.h: No such file or directory
hello.c: In function ‘main’:
hello.c:5: warning: incompatible implicit declaration of built-in function ‘printf’

At this point I know very little about C or the compiler. I created a folder(C) in my home folder, used gedit to save hello.c in the C folder I had created, then used gcc hello.c

Is this a matter of being in the wrong folder? I found /usr/lib/gcc but was not allow to save a file.

Can someone point me to an article about how to set up and use gcc in lmde. Or if it is a simple mistake, tell me where I need to be doing the compiling.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
vortex59
Level 3
Level 3
Posts: 149
Joined: Wed Aug 20, 2008 9:09 am
Location: Timișoara, România

Re: Help with setting up and using the GCC compiler

Post by vortex59 »

You have to install libglib2.0-dev the development library for Glib. Usually the "xxx.h" file are in /usr/include folder (or /usr/include/some-name).
"A scientist is someone whose curiosity survives education's assaults on it". Sir Hermann Bondi
Sleven

Re: Help with setting up and using the GCC compiler

Post by Sleven »

I installed the libglib2.0-dev package.

Still getting an error when I try to compile from the C folder I created in my home folder. Do I need to set a default path to the compiler and/or libfiles, or do I need to create a C folder in another place?
User avatar
vortex59
Level 3
Level 3
Posts: 149
Joined: Wed Aug 20, 2008 9:09 am
Location: Timișoara, România

Re: Help with setting up and using the GCC compiler

Post by vortex59 »

Strange (for me!). Usually gcc is installed by default in linux and you don't have to do anything in settigs related to this compiled (except some suplemental dev libraries). You do not have to set the path to gcc.
However try:
$ locate stdio.h to see were is (or if it is there) the stdio.h file

and

$ sudo apt-get install build-essential to install the "must have" libraries.
"A scientist is someone whose curiosity survives education's assaults on it". Sir Hermann Bondi
Sleven

Re: Help with setting up and using the GCC compiler

Post by Sleven »

sleven@unit1 ~ $ locate stdio.h
/usr/include/stdio.h
/usr/include/bits/stdio.h
/usr/include/c++/4.4/tr1/stdio.h
/usr/include/glib-2.0/glib/gstdio.h
/usr/lib/perl/5.10.1/CORE/nostdio.h


sleven@unit1 ~ $ sudo apt-get install build-essential
[sudo] password for sleven:
Reading package lists... Done
Building dependency tree
Reading state information... Done
build-essential is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.

Shouldn't I be able to compile from any folder I create and work in? Also this a C tutorial not C++
User avatar
vortex59
Level 3
Level 3
Posts: 149
Joined: Wed Aug 20, 2008 9:09 am
Location: Timișoara, România

Re: Help with setting up and using the GCC compiler

Post by vortex59 »

Yes, you should be able to compile from any folder! Never met something like that!
"A scientist is someone whose curiosity survives education's assaults on it". Sir Hermann Bondi
User avatar
vortex59
Level 3
Level 3
Posts: 149
Joined: Wed Aug 20, 2008 9:09 am
Location: Timișoara, România

Re: Help with setting up and using the GCC compiler

Post by vortex59 »

Back again after a short chat with a friend: try gcc -I/usr/include hello.c
The -I flag force the compiler to "look" in the folder /usr/include where stdio.h is present (as you proved by "locate stdio.h").
If you still get the error it must be a gcc configuration error (which is something rare. I used Linux Mint since Elyssa (5) version and had never such an error in any version).

Another idea is to use the cpp (c preprocessor) and somewhere in the console (long: ~950 lines) output you must see something like:

# 936 "/usr/include/stdio.h" 3 4 - this means the preprocessor finished to load the stdio.h file
# 4 "hello.c" and returned to the main program.

....here comes the source code of your program
"A scientist is someone whose curiosity survives education's assaults on it". Sir Hermann Bondi
Sleven

Re: Help with setting up and using the GCC compiler

Post by Sleven »

Thought it might have something to do with tracking sid instead of squeeze, so I booted into lmde squeeze and started over,
created a folder, C, in my home folder
copied and pasted the program from the tutorial into gedit,
saved it as hello.c
opened a terminal in the C folder
gcc hello.c -same errors
gcc -l/usr/include hello.c -produced the same erorrs

I'm including a screen shot so you can see exactly what I'm doing, maybe it is something simple I'm doing wrong.
This is my first attempt at learning C, so I started at the beginning, and don't know how to use cpp, sorry vortex
The tutorial is in the background with C folder, gedit, and terminal on top.
Screenshot-4.png
If everything is set up correctly and should work the way I'm doing it, I can go ask in a C forum why it is not working.
I just wanted to be sure I was going about it in lmde correctly before asking anywhere else.
Sleven

Re: Help with setting up and using the GCC compiler

Post by Sleven »

Problem solved guys, in the code itself

#include < stdio.h> is very different than
#include <stdio.h>

there was a space between < and stdio.h

Thanks to everyone that tried to help.
User avatar
vortex59
Level 3
Level 3
Posts: 149
Joined: Wed Aug 20, 2008 9:09 am
Location: Timișoara, România

Re: [SOLVED]Help with setting up and using the GCC compiler

Post by vortex59 »

Glad to see it's OK! However, in gcc -I/usr/include it is I( capital leter i, not l). It's just in case :D .
"A scientist is someone whose curiosity survives education's assaults on it". Sir Hermann Bondi
Locked

Return to “Software & Applications”