 |
 |
 |
 |
| Programming & Packaging A place to discuss programming and packaging. |

5th August 2012, 06:07 AM
|
|
Registered User
|
|
Join Date: Aug 2012
Location: Nebraska
Posts: 2

|
|
Beginning to program in C in Linux
Hello everybody! I'm new to the world of Linux and I'm still getting used to things and how linux works. I like it a lot so far, but I have some questions about programming.
I'm not a complete programming noob- I've done some work with programming PIC18 microcontrollers using machine assembly code and I'm interested in learning C. I'm used to using Microchips IDE, so I'm accustomed to a fairly straightforeward programming environment where I enter code, hit a compile/run button, and see what happens. I want to move up to programming a computer rather than a microcontroller, and though I'd fully believe a computer could be programmed with machine assembly code, I'd rather not be the guy stuck with that job.
First off, is there a programming environment that does that in linux? If not could someone point me in the direction of some good C programming software? At the moment I'm stuck with this thing called VIM so at the very least I'd like to know how to execute code I've written in VIM. I guess I'm essentially asking how I get started. Just give me all the software and the knowhow I need to get the words "Hello World!" to pop up on screen and I can take it from there.
Second, assuming I manage to get a message of my choosing to pop up on screen, what sort of things can knowledge of C programming do for me? Something I think would be nice is a program that automatically says "Yes" when my antivirus asks me If I wnat to conduct a scan. What other possibilites are there for me?
Third (and this is a bit off topic I know but this has been annoying me a bit for some time now) how do I change the background of Fedora 17's user loggin screen? The default is some fireworks in the sky, but I'm getting rather tired of seeing the same thing at the loggin and not knowing how to do anything about it.
Thanks everybody!!
|

5th August 2012, 08:21 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 121

|
|
|
Re: Beginning to program in C in Linux
With Vim, you would just write your program into a C source file, or several of them.
If you wrote a simple program into a file called hello.c, you could compile and run it outside Vim like this:
Code:
gcc hello.c -o hello
./hello
For more complex programs, you might use GNU Make or some other tool to automate the compiler invocations, because multi-file programs often take some more steps to build.
There are more integrated enviroments like Eclipse and Qt Creator in Fedora. However, just the plain Unix-like GNU/Linux comman environment provides plenty of tools for programming in C.
|

5th August 2012, 09:23 AM
|
|
Registered User
|
|
Join Date: Apr 2010
Location: Earth
Posts: 857

|
|
|
Re: Beginning to program in C in Linux
you could also try the codeblocks or Anjuta IDE. Both is in the fedora repository.
|

5th August 2012, 10:06 PM
|
 |
Registered User
|
|
Join Date: Nov 2006
Location: Detroit
Posts: 4,616

|
|
|
Re: Beginning to program in C in Linux
Quote:
Originally Posted by Bosscheesemo
Just give me all the software and the knowhow I need to get the words "Hello World!" to pop up on screen and I can take it from there.
|
For C programming I use Emacs. You can install it via yum by running this command (as root):
Emacs has a "Compile" menu option which by default tries to run make. So if you have a Makefile in the current directory then that will be used. If you don't, then you can set a custom compile command (e.g. gcc -o hello hello.c) with a special commented first line in your source code file. On subsequent compilations that custom compile command will be remembered, and you'll have the option of changing it. That special first line is of the form:
Code:
/* -*- mode: c; compile-command: "whatever command(s) you want"; -*- */
Only the stuff in quotes needs changing.
For example, in the pictures below you'll see how to compile and run a "Hello, world!" C program all within Emacs:
__________________
OS: Fedora 18 x86_64 | CPU: AMD64 3700+ 2.2GHz | RAM: 2GB PC3200 DDR | Disk: 160GB PATA | Video: ATI Radeon 7500 AGP 64MB | Sound: Turtle Beach Santa Cruz CS4630 | Ethernet: Realtek 8110SC
|

6th August 2012, 12:05 AM
|
|
Registered User
|
|
Join Date: Aug 2012
Location: Nebraska
Posts: 2

|
|
|
Re: Beginning to program in C in Linux
I tried that Codeblocks environment and I think I like that. Thanks for the help! I'll make sure to ask you fine gents first int he future if I need anything! Thanks again and happy programming!
|

6th August 2012, 07:00 AM
|
|
Registered User
|
|
Join Date: Nov 2007
Posts: 61

|
|
|
Re: Beginning to program in C in Linux
microchips new ide mplab-x is netbeans based which was in fedora last time i tried (f16) but i think i remember reading something about it being dropped.
i've just started using geany for c programming and i like it, very easy to use, describes itself as "A fast and lightweight IDE." vim and emacs good but steep learning curve.
|

7th August 2012, 11:08 AM
|
 |
Banned (for/from) behaving just like everybody else!
|
|
Join Date: Jul 2007
Location: Beijing, China
Posts: 1,307

|
|
|
Re: Beginning to program in C in Linux
If you're going to release your code as a package that can compile on a wide variety of systems, you may also add the GNU Auto-tools to your developing environment. Red Hat has a free book on this topic http://sources.redhat.com/autobook/
But for now you can just as well postpone this topic as you're learning the basic stuff first.
__________________
I believe in nerditarianism. I read FedoraForum for the Fedora-related posts.
|

8th August 2012, 04:22 AM
|
|
Registered User
|
|
Join Date: Oct 2010
Location: Canberra
Posts: 540

|
|
|
Re: Beginning to program in C in Linux
Given that you come from a microcontroller background, I am assuming that you have a good grasp of variables and addresses - that will be useful when programming in C.
I spent many years maintaining 500K lines of C code with nothing more than vim and command lines programs. Until you start using large libraries I would not bother with an IDE. They often take a lot of learning to use well, and that is easier if you understand what is happening behind the scenes.
If you haven't already, get a copy of "The C Programming Language" by Kernighan and Ritchie. Its not a very big book and is quite easy to read. Work through the examples and exercises in it.
At first I would just use gcc on the command line to build the programs. Then you can automate it a bit with some shell scripting. Then move on to using the 'make' command. Later you should look at the autotools suite - its a lot of learning, but worth the effort if you want to publish your work.
For your first programs I would recommend staying away from GUIs. The C based alternatives are GTK and Motif. Both are large and complex. Once you get confortable with using libraries then perhaps move to GUI programs. An alternative is to use something like Python for the GUI interface with the work being done by your C program.
While C is a powerful language, it has its limits when trying to build large systems. For that you may want to consider moving to C++ or some other object oriented language. Something to think about in a few years time.
All the best, and drop by occasionally to let us know how you are getting on.
|

9th August 2012, 04:00 PM
|
 |
Registered User
|
|
Join Date: Jun 2004
Location: Laurel, MD USA
Posts: 5,449

|
|
|
Re: Beginning to program in C in Linux
Quote:
Originally Posted by pjoh
microchips new ide mplab-x is netbeans based which was in fedora last time i tried (f16) but i think i remember reading something about it being dropped.
i've just started using geany for c programming and i like it, very easy to use, describes itself as "A fast and lightweight IDE." vim and emacs good but steep learning curve.
|
It doesn't matter that netbeans was dropped, just get the installer file from
http://netbeans.org/downloads/
and it installs just fine. The job of updating that would usually be handled by yum can be done by netbeans itself by using the Help menu (Help -> Check for Updates).
If you install it under your home directory you can do the update yourself but if you install it in some system area like /usr/local you'd have to run it as root, do the update and then quit so you can do your work as the user.
|

13th August 2012, 04:59 AM
|
|
Registered User
|
|
Join Date: Oct 2011
Posts: 99

|
|
|
Re: Beginning to program in C in Linux
Of course, you could build yourself a make file that's executable and then just click it when you want it... (I think...)
|

13th August 2012, 03:53 PM
|
|
Official Gnome 3 Sales Rep. (and Adminstrator)
|
|
Join Date: Jul 2011
Location: Leamington Spa, UK
Age: 30
Posts: 1,707

|
|
|
Re: Beginning to program in C in Linux
Quote:
Originally Posted by Ravenshade
Of course, you could build yourself a make file that's executable and then just click it when you want it... (I think...)
|
You could, although it'd be fairly non-standard. You'd need to add a shebang to the start of the Makefile: "#!/usr/bin/make -f" or similar.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Current GMT-time: 07:54 (Tuesday, 21-05-2013)
|
|
 |
 |
 |
 |
|
|