newbie: steps to create and compile c program in SUSE

This is a discussion on newbie: steps to create and compile c program in SUSE within the Linux Programming forums, part of the Platform Specific Boards category; Hi ! I am a newbie and have been working in windows XP and bloodshed dev-c++ compiler b4, but recently ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    91

    newbie: 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 and notepad. vi. I have no idea which to use to create a program.

    Any help would be appreciated !!!

  2. #2
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190
    First thing first: programming in linux is similar to programming in windows. So the whole idea is that you create a file with some code in it and then feed it to the compiler, so that it can create an "exe"-file.

    To create and edit the file with C code you can use anything you want - kwrite, vim (or vi), emacs, kate etc. All of these are simple (more or less) editor programs similar to notepad in win32.

    Then we have the compiler part. The best choice is the GNU C Compiler. It must be preinstalled on the system. So how do you use it? Follow these steps:

    1. Create a .c file in some directory, say /home/your_username/c/
    2. Make some coding and save the file in the newely created dirctory
    3. Then go to the console an browse to the folder where the .c file is placed. You can do this by typing:
    Code:
    cd /home/your_username/c/
    And then pressing Enter.
    4. Now, let's compile the program. Type:
    Code:
    gcc name_of_your_file.c -o name_of_exe_file
    Press Enter.
    5. Now the program is compiled and you can execute your program by:
    Code:
    ./name_of_exe_file
    Many people find it convinient using emacs as a C editor. But this editor is rather complex in use, so I don't know if it is the right choice for you yet.

    You can also use KDevelop. It's similar to Dev-C++ (and others like VC++, BCB etc.), and has a nice front-end so you do not need to compile your project from console. If you can, use KDevelop.
    Last edited by MathFan; 05-21-2005 at 02:02 PM.
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

  3. #3
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190
    I got a message saying cannot find file stdio.h.
    That's rather strange though. stdio.h should have been present on your computer, to be more exact - it should be in /usr/include/ directory. That it's missing means that probably the "glibc" library is not installed. Try to install it using SUSE's package manager
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

  4. #4
    Registered User
    Join Date
    Feb 2005
    Posts
    91
    thank for the reply MathFan.

    Here are the problems i faced , I did exactly as you said,

    first error : it says gcc : no such command, so I tried cpp
    second error : it says stdio.h : no such file or directory

    I am running linux on Vmware and I downloaded SUSE 9.1 personal from the website "www.linuxiso.org",

    Two questions:
    I presume I can download SUSE package manager from SUSE's website, but Since I am running linux through Vmware do you have any idea how to install this package on it ????

  5. #5
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190
    Is gcc missing?? Hmmm... I thought it was a default for most linux dists. You will probably need to downlod and install it as well.

    That about the package manager. I think it is preinstalled. I'm not familiar with SUSE, but I think it uses the so-called rpm-packages. To install a package, you should first of all find it somewhere, for example you can search for rpm-s here or just use google. When you have downloaded a package, you should get root, that is by typing:
    Code:
    su
    Then type in your password and browse to the download location of the rpm-file. Then type:
    Code:
    rpm -ivh name_of_package.rpm
    You will probably get some dependecy errors, like: "package some_package has to be installed". You must satisfy these dependencies by downloading and installing all needed packages.

    Another thing is: Why did you choose SUSE? If you ask me Mandrake or Fedora are a better choice for a beginner. They are easy to install - and the gcc, glibc and others are present on the installation cd-s, so you won't have to look for them elsewhere. When installing Mdk Or Fedora, you will be asked if you want to install development tools. If you choose that option, everything will be installed for you.

    By the way: are you sure that the gcc and glibs packages are not on your SUSE cdrom-s (or dvd-s)?
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

  6. #6
    Registered User
    Join Date
    Feb 2005
    Posts
    91
    I dwonloaded fedora core 3 but after all these tries I keep ketting media check failure.

    I have a pretty slow connection so its hard for me to download, so the next I saw was suse which was only one CD so I went ahead and downloaded it. I want to download mandrake but its 3 CD's it will take me some time to get it, so I was wondering if I could get aways with SUSE.

    Looks like not so I guess I will have to go with MANDRAKE, but it will take me while to get it, I am downloading from "www.linuxiso.org"

  7. #7
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190
    The problem is that SUSE is not a free OS like Mandrake and Fedora. A full version of it will cost you money, while the cd you downloaded is only a kind of a preview. It doesn't include the usual things other linux distros have as default.

    Yes, mandrake is a good choice. Be sure though to choose "development packages/software" in the "Package Selection" step during the installation of mdk.
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

  8. #8
    Registered User
    Join Date
    Feb 2005
    Posts
    91
    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 ?

  9. #9
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190
    cpp is only a preprocessor - it's not the compiler (but, sure, it's a part of the GNU C and as far as I know is needed for gcc to run). Also libgcc is needed for the gcc to run. So that's a good start. Now, the only thing you need to do is to go here and download the gcc-3.3.3 package and install it. Then try to compile your files.

    If it doesn't work, tell me.
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

  10. #10
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190
    Take a look at the page I gave you in the previous post. Note that under the download mirror links, it lists the required packages. You MUST have all of these to get gcc to install. So if they are not present on your system, you will have fetch and install them too.

    edit: You must make sure that the version of the packages match. Like: if you have gcc-3.3.3, you must also have libgcc-3.3.3. Another thing is that since you have SUSE, you must look for rpm-packages for SUSE, and not for, say mandrake. Sometimes packages form other systems may work on SUSE, but it is not advised to mix them like this.

    edit2: One more thing: glibc-devel is NOT the same as glibc!
    Last edited by MathFan; 05-23-2005 at 08:02 AM.
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

  11. #11
    Evil Archmage KntTwist's Avatar
    Join Date
    Apr 2005
    Posts
    2
    I use SuSE 9.2, and it was also my first intro to Linux. For coding in C, I use Kate, 'cause it has a handly little terminal emulator within.

    But as for GCC, try http://gcc.gnu.org/ It may help you figure out a few things.

  12. #12
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    Quote Originally Posted by mathfan
    Now the program is compiled and you can execute your program by:
    Code:
    ./name_of_exe_file
    Thank you very much! I could compile C programs but not run them. All because I forgot the "./" . . . .

    dwk

  13. #13
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Quote Originally Posted by MathFan
    cpp is only a preprocessor - it's not the compiler (but, sure, it's a part of the GNU C and as far as I know is needed for gcc to run). Also libgcc is needed for the gcc to run. So that's a good start. Now, the only thing you need to do is to go here and download the gcc-3.3.3 package and install it. Then try to compile your files.

    If it doesn't work, tell me.
    A friend of mine had the same problem with SuSE 9.1.. we were scratching our heads for a minute, wondering why a Linux distro would not have a C compiler, but anyway.. We fixed the problem with YAST - and I would recommend this as a solution for the O.P.

    YAST works nicely as you should have few dependency problems.

    @ gemini_shooter:

    Open Yast up to and have another look for gcc - it should show up there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you create, edit and compile C code with a C++ IDE?
    By nerdpirate in forum C Programming
    Replies: 4
    Last Post: 05-31-2008, 01:54 AM
  2. Newbie needs help..
    By xpress urself in forum C++ Programming
    Replies: 3
    Last Post: 07-26-2007, 07:22 PM
  3. a program to create months in a year newbie question
    By robasc in forum C Programming
    Replies: 2
    Last Post: 03-05-2005, 04:41 PM
  4. how do i compile a program that deals w/classes?
    By Shy_girl_311 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2001, 01:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21