creating make files

This is a discussion on creating make files within the Linux Programming forums, part of the Platform Specific Boards category; can someone please give me an example of a makefile. what i am trying to do is compile two files ...

  1. #1

    creating make files

    can someone please give me an example of a makefile. what i am trying to do is compile two files with gcc by using the make comand. right now i have

    gcc -o file1 file1.c
    gcc -o file2 file2.c

    and if i issue the make command i get

    make: Fatal error in reader: Makefile, line 3: Unexpected end of line seen


  2. #2
    Registered User
    Join Date
    Aug 2001
    Are you trying to compile two programs, or simply compile a single program that has two .c source files?

    Either way, you're not supposed to generate the Makefile yourself. You generate the and the think. There might be programs to help. I'm rather new to programming in Linux).

    $info automake

    In the former case, examples->ctags&etags is a good example.

    In the latter case, either use a different example or just read the rest of the docs(which are better than your average info help).
    All generalizations are false

  3. #3
    Registered User Xaviar Khan's Avatar
    Join Date
    Sep 2001

    Talking actually...

    You can and should create your own make file. Just to be sure you know what you want.

    I'm using Redhat Linux 6.2 on an i686
    not sure if that would affect your makefile any, but the type of OS you are running would no doubt have an effect on the syntax of the things you use.

    Here's a look at my makefile.
    CC      = gcc
    PROF    =
    OPTOMIZ = -O2
    DEBUG   = -g3
    WARN    = -Wall
    C_FLAGS = -c -O -Wall -g3
    L_FLAGS = -static -g
    CRYPT   = -lcrypt
    SYSTEM  =
    O_FILES = act_comm.o act_info.o act_move.o blah blah blah
    (i'm not sure you need the names of my '.o' files... but here is wher you put your files to be compiled)  be sure to leave a '~' at the end or bad things will happen ;)
    I'm also using the concurrent versioning system (CVS) so things are subject to changes if you are not.

    Xaviar Khan
    Shards of Destiny (SoD)
    Reach us with any MUD client at
    port 9000.
    | Html/Java support added, |
    | '' |

  4. #4
    Registered User Strider's Avatar
    Join Date
    Aug 2001
    Your best bet is to be very specific and break it down into the separate parts.

    # Makefile
    FILES = file1.c file2.c
    OBJECTS = file1.o file2.o
    all:      $(OBJECTS)
              gcc -o NameOfExecutable $(OBJECTS)
    file1.o:  $(FILES) $(OBJECTS)
              gcc -c file1.c
    file2.o:  $(FILES) $(OBJECTS)
              gcc -c file2.c
    Also make certain there is no CrLf after the last item.

    Last edited by Strider; 09-06-2001 at 02:54 PM.
    One Ring to rule them all, One Ring to find them,
    One Ring to bring them all and in the darkness bind them
    In the Land of Mordor where the Shadows lie.

  5. #5
    a simple hint with the last example

    parameter_name : dependent files (a.out and the files you'll use )
    <tab very imp ok> commands


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how gnu make tells if file's been changed?
    By thinhare in forum C Programming
    Replies: 2
    Last Post: 03-19-2008, 03:10 AM
  2. Make Files
    By shipyard in forum C Programming
    Replies: 6
    Last Post: 03-13-2005, 11:43 AM
  3. creating multiple files
    By lime in forum C Programming
    Replies: 8
    Last Post: 01-01-2004, 01:55 PM
  4. How To Make The Program Installed In Program Files Folder?
    By javacvb in forum Windows Programming
    Replies: 4
    Last Post: 11-05-2003, 04:33 PM
  5. Creating files then Hiding them or making them
    By Kyoto Oshiro in forum C++ Programming
    Replies: 7
    Last Post: 03-09-2002, 06:30 PM

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