Connect with us

Programming c on raspberry pi

Discussion in 'Microcontrollers, Programming and IoT' started by Rajinder, Mar 18, 2018.

  1. Rajinder

    Rajinder

    411
    7
    Jan 30, 2016
    Hi
    I am looking to program in c on the raspberry pi 3.
    It comes installed with NOOBS.
    Do i need to install anything else to get my c programs up and running ie complier or OS.
    I am a newbie to the raspberry PI so not sure.
    Thanks in advance.
     
  2. hevans1944

    hevans1944 Hop - AC8NS

    4,258
    2,008
    Jun 21, 2012
    As a newbie, you should visit this page FIRST and then follow the links you find there.
     
  3. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,213
    2,695
    Jan 21, 2010
    Also note that any compiler you find will probably default to C++
     
  4. Harald Kapp

    Harald Kapp Moderator Moderator

    9,396
    1,919
    Nov 17, 2011
  5. Rajinder

    Rajinder

    411
    7
    Jan 30, 2016
    Thanks for the information. Even if the compiler defaults to c++, i think i can still use c ? Is that not correct?
     
  6. Harald Kapp

    Harald Kapp Moderator Moderator

    9,396
    1,919
    Nov 17, 2011
    Usually yes.
     
  7. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,213
    2,695
    Jan 21, 2010
    C++ is more strict with types than C. You'll find that some C code will require explicit type-casting in order to compile.

    Also there are more reserved words in C++ and if you choose one as your variable (or more likely you are compiling some code where someone else has used one) then you'll have some trouble.

    If you want a longer list, see here.
     
  8. LukeDupont

    LukeDupont

    19
    1
    Apr 15, 2018
    It might do you some good to familiarize yourself with Linux. Grab an ISO of Ubuntu or Linux mint, install it on a virtual machine like virtualbox or an unused PC laying about, and use it for a few weeks as your main computer. Learn to install packages, find your way around the terminal, and compile using gcc. You might even find you like it better than Windows or MacOS, if you're like me.

    But, the reason I say to do that is because the raspberry pi is a stripped down, bare bones computer running a stripped down, bare bones installation of Debian with some odd configuration stuff thrown on top, so you may find it a bit challenging compared to a "normal" Linux distribution at first.

    That said, Linux, the Raspberry Pi, and C/C++ are all wonderful, and you'll learn a lot about all aspects of computers and programming if you stick with it.

    I think if you do that, most of your questions will be quickly answered. Maybe find some C tutorials on youtube that are aimed at compiling on Linux, and not just using some IDE (which, granted, you could also use instead. Code Blocks comes to mind).

    Edit: Okay, I'll answer some of these questions directly.

    "gcc" and "g++" are the gnu c compilers that will be installed, or at least available in the repositories of any Linux Distro.

    Open a terminal and type "gcc -v"
    If it outputs version info, gcc is installed.

    Otherwise, install it with the command "sudo apt install gcc"
    "sudo" is for super user do, and will prompt you for a password. Asterisks won't appear as you type - just type it and press enter.
    "apt install" tells apt, your package manager, to install a package.
    "gcc" is the GNU C Compiler package that you're installing.

    To then compile a c file, let's say "hello.c", type:
    gcc hello.c -out 'hello'
    This will make a binary file called "hello" which you can run by typing "./hello"

    You might also find programs like "cowsay", "htop", "nano", and "vim" to be fun or useful to mess around with while learning. Try typing them into the terminal and seeing what happens :)
     
    Last edited: Apr 18, 2018
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-