Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! uniquerockrz's Avatar
    Join Date
    Feb 2011

    Question Creating Makefiles in Linux for installing programs

    I have written a console program in C named main.c.

    I want to turn it into an application, so that using a Makefile and 'make' and 'make install' commands one is able to install that in his/her computer.

    Any ideas how to do that? I have searched tutorials for making the Makefile but they just tell me the way to compile the source files, not "install" them.

    PS, I use Fedora 15 and Code::Blocks Ide, if that is of any help.

    PPS : I have seen that copying the executable produced by gcc to /usr/bin directory does has the same result as installing. Is that what 'make install' command does?

  2. #2
    Create a Makefile and put it in the same dir as your *.c file. Here's a very basic example of a Makefile:
    CC      = /usr/bin/gcc
    STRIP   = /usr/bin/strip
    SRC     = myprog.c
    OBJ     = myprog.o
    EXE     = myprog
    .c.o: $(INC)
            $(CC) $(CFLAGS) -c $*.c
    all: $(EXE)
            $(STRIP) $(EXE)
            rm -f *.o rm -f *% $(EXE)
    $(EXE): $(OBJ)
            $(CC) -o $(EXE) $(OBJ) $(LIBS)
    install :
            cp $(EXE) $(BINDIR)
    It will compile myprog.c into a binary named myprog when you run "make". It will copy it to the $BINDIR location (which you can specify various ways) when you run "make install"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts