Compiling C in KDE

Dotan Cohen dotancohen at gmail.com
Mon Jul 10 23:23:09 UTC 2006


On 11/07/06, James Gray <james at grayonline.id.au> wrote:
> Somewhere between Kdevelop 1.x and the current version they switched
> from using simple "gmake" Makefiles to the full qmake stuff.  This
> confuses the hell out of newbies (like yourself) but us really good if
> you're collaborating on a large project.

I'll start searching for 1.0<kdevelop<3.3 and install it!

> Here's the good news:  you can still use standard "gmake" makefiles if
> you want, but you'll be compiling on the command line until you learn
> the internals of a Kdev project file.
>
> Here's a VERY simple Makefile I used for most of the basic programming
> tasks I did at Uni:
>
> CC=gcc
> PROG=mycprog
>
> $(PROG):        $(PROG).o
>                 $(CC)  -o $(PROG) $(PROG).o
>
> $(PROG).o:      $(PROG).cpp
>                 $(CC)  -c $(PROG).c
>
> clean:
>                 rm -f $(PROG) *.o
>
> all:            $(PROG)
>
> proper:         clean $(PROG)
>
> ALWAYS use tabs in makefiles!  So it's:
> $(PROG):<tab><tab>$(PROG).o
> <tab><tab><tab>$(CC)....

I don't really understand it yet, but I will try to figure out what it
all means when I have thee time.

> Save it as "Makefile" in the same directory as your source code.  Now
> edit the "PROG=mycprog" line and replace "mycprog" with the file name of
> your ".c" file for the assignment without the ".c".  Make sense?
>
> Now, whenever you edit your file in Kdev, you simply save it, open a
> command prompt, change to the same directory your assignment is in (Kdev
> can do this right in the IDE) and type "make" and hit enter.  Voila!!
> You now have an executable called "mycprog" in the same directory as the
> source.
>
> This is a small amount of work for a lot of gains.  If you add a header
> file, "mycprog.h" simply add it to the "$(PROG).o:" as a dependant like
> this:
>
> $(PROG).o:      $(PROG).cpp $(PROG).h
>
> Now, whenever you edit (and save) the "mycprog.h" file, make will see
> the change and recompile the object file and relink the executable for
> you :)  Simple huh?
>
> Makefiles can save you a LOT of time and the one above is a simple
> template that only requires you to change one line to run it against a
> different C project.
>
> Googling "gmake" and "Makefile syntax" should help even further :)
>
> > I've another day to turn in my C homework. I've either got to get this
> > working in the next hour or so, or I've got to go to the university
> > and punch out this assignment on a windows machine. And I'd rather do
> > it at home, on Kubuntu, thank you!
>
> Ok - so my help will probably come too late, but maybe for the next
> assignment huh?

Well, I doubt that I will be doing things that way for the university,
because come test time I won't know the 'right' way (the way we were
taught) to do what they want. However, if I do get into some simple
development work, I'll be rereading this post. I did patch and compile
F-spot not long ago, and I can see where knowing at least the basics
is important for even an end user.

In any case, I'm in Mechanical Engineering and not CS, so if I do get
any deeper into this, then it's for my own fun. Oh, what fun!

> Good luck!

Thanks. Tell me that again on Friday- that's our final exam this semester.

Dotan Cohen
http://essentialinux.com




More information about the kubuntu-users mailing list