GIDForums  

Go Back   GIDForums > Computer Forums > Computer Software Forum - Linux
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-May-2005, 10:57
batrsau batrsau is offline
New Member
 
Join Date: Mar 2005
Posts: 15
batrsau is on a distinguished road

Steps to create and compile c program in SUSE


Hi !

I am a newbie and have been working in windows XP and bloodshed dev-c++ compiler b4, but recently I have made the decision and managed to switch to linux. I started by using SUSE 9.1 personal linux on Vmware workstation.

I apologize for my dumbness, but I have no clue to create and compile a c program in SUSE. Can anyone please give me a few steps on how to do that.


I opened up something called root shell and wrote the following command

" cpp pathname/filename.c"

I got a message saying cannot find file stdio.h. I am tottally lost about this,can any please give me the right way to to write a program and compile it. There is also something called kwrite, notepad and vi. I have no idea which to use to create a program.

Any help would be appreciated !!!
  #2  
Old 21-May-2005, 14:39
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi batrsau and welcome to the wonderful world of Linux!

First of all, do not use a root shell. You should avoid doing things as root when possible. Most of the time it is not necessary to be root to compile a program.

The command you want to use is gcc or g++ for a C++ program. cpp actually calls the pre-processor, which is automatically called by the compiler.

The basic use of g++:
CPP / C++ / C Code:
g++ myprogram.cpp -o myprogram

This will take a single file, compile it and link it into a binary file called myprogram.

Hope this helps,
d
  #3  
Old 22-May-2005, 02:18
batrsau batrsau is offline
New Member
 
Join Date: Mar 2005
Posts: 15
batrsau is on a distinguished road
Thanks for the reply Mod,

I tried the steps you told but I get some problems :

error : stdio.h : no such file or directory found

I downloaded this linux version from "www.linuxiso.org" and I am presuming it doesn't have the c compiler and library installed in it.

Two questions :

1. Can you tell me what package to download from SUSE's website that will give me the library and compiler.
2. Since I am running this linux on Vmware I would also need some advice on how to install it on the SUSE through Vmware.

Thanks again
  #4  
Old 22-May-2005, 07:01
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi batrsau.

I believe that the compiler at least is installed if the command g++ actually started. It may be a pathing issue it sounds like because it can't find stdio.h.

Here is a couple more suggestions:
  1. It appears that this is a C program and not a C++ program. Try using gcc instead.
  2. Go to a folder called /usr/include look for a file called stdio.h.
  3. If you can not find stdio.h under /usr/include, try using this command to see if it can be found anywhere:
    Code:
    whereis stdio.h
  4. If you do find stdio.h, but the gcc command didn't work, try using this command to compile:
    Code:
    gcc myprogram.c -I /usr/include -o myprogram
    and see if that works. If it works like this, then you need to set some environmental variables that for some reason didn't get set.

If none of this works, then I will try to help you get the necessary files installed.

Good luck!
d
  #5  
Old 22-May-2005, 22:05
batrsau batrsau is offline
New Member
 
Join Date: Mar 2005
Posts: 15
batrsau is on a distinguished road
Thanks for the reply Mod.

Unfortunately, I didn't find the file stdio.h, I used the command you gave me as and the closest thing I found was in the folder /usr/share/man/man3/

and the files have a weired extension as stdio.3.gz, some other files were stdin.3.gz, stdout.3.gz and stpcpy.3.gz

I downloaded this linux version from "http://www.linuxiso.org" its SUSE 9.1 personal-x86 and I am using Vmware Workstation 5.0 to run this linux.

I don't if suse was bad idea, but I have tried a few before, I tried to install FC3 but I never get a clean media check for CD1 and CD3, the md5sums were fine and I have wasted quite a lot of Cd's on that, I have tried KNOPPIX and College Linux but the use and installtion and are a little weired, then I decided to go to SUSE and now this, I guess the next option would be to get mandrake if nothing works.

The sad part is I have a pretty slow connection so it takes a while to get all this stuff. I haven't given up hope...... yet !!!!!!
  #6  
Old 22-May-2005, 22:20
batrsau batrsau is offline
New Member
 
Join Date: Mar 2005
Posts: 15
batrsau is on a distinguished road
Sorry for the double post !!!!

I ran yast2 on SUSE 9.1 and these are the packages I could find which puzzles me even more now :

Package Summary Size Version
cpp The GCC preprocessor 3.6MB 3.3.3-41
libgcc C compiler Runtime library 39.2kB 3.3.3-41

Does this mean I already have gcc installed but why can't I run it then ?
  #7  
Old 23-May-2005, 16:25
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi batrsau.

It does seem strange that gcc would be there, but the include files are not. They should be installed anytime that gcc is installed.

Can you tell me where your gcc is installed? It is most likely in /usr/bin or /usr/local/bin. Your header files should be included in a path like /usr/include or /usr/local/include respectivelly.

You can install a new version of gcc if you would like. It is a rather large download file and will take at least an hour to build. You can find the current releases at this ftp site. If you are going to build brand new, you should probably go with either 3.4.3 or 4.0.0. The only reason to hold off on 4.0.0 is that it is the first release in that branch. I just installed 4.0.0 and have not had any problems though.

If you want to install from scratch, let me know and I will give you abbreviated instructions. It is not difficult, but it does take some time.
  #8  
Old 03-Jun-2007, 19:49
Mevsthevoices Mevsthevoices is offline
New Member
 
Join Date: Jun 2007
Posts: 1
Mevsthevoices is on a distinguished road

Re: newbie: steps to create and compile c program in SUSE


To get them there is an even easier way
sudo install get-apt build-basics
OR
sudo install get-apt build-basics

As for the library try /usr/include
 
 

Recent GIDBlogPython ebook by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[TUTORIAL] Calling an external program in C (Linux) dsmith C Programming Language 4 22-Apr-2005 13:30

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:42.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.