#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    india
    Posts
    28
    Rep Power
    0

    make file creation


    see i am trying to make "make file"

    but i am getting error .pls help me out

    these are the files i used

    1)main.c

    include <stdio.h>
    #include "header.h"

    char *AnotherString = "Hello Everyone";

    main()
    {
    printf("Running...\n");

    /*
    * Call WriteMyString() - defined in another file
    */
    WriteMyString(MY_STRING);

    printf("Finished.\n");
    }


    2)header.h

    #define MY_STRING "Hello World"

    void WriteMyString();




    3))writemystring.c



    extern char *AnotherString;

    void WriteMyString(char *ThisString)
    {
    printf("%s\n", ThisString);
    printf("Global Variable = %s\n", AnotherString);
    }





    error i am getting


    make: *** No rule to make target `WriteMyString.o', needed by `main'. Stop.





    mymake


    #
    # Makefile
    #
    SOURCES.c= main.c WriteMyString.c
    INCLUDES= header.h
    CFLAGS=
    SLIBS=
    PROGRAM= main

    OBJECTS= $(SOURCES.c:.c=.o)

    .KEEP_STATE:

    debug := CFLAGS= -g

    all debug: $(PROGRAM)

    $(PROGRAM): $(INCLUDES) $(OBJECTS)
    $(LINK.c) -o $@ $(OBJECTS) $(SLIBS)

    clean:
    rm -f $(PROGRAM) $(OBJECTS)
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Try adding a dependency list at the end of the make file:

    main.o: header.h
    WriteMyString.o: WriteMyString.c

    You can have gcc generate the dependency list for you with:
    gcc -MM main.c WriteMyString.c

    Also, where is the compiler specified in your makefile? I see no definition for the macro, LINK.c .

    Also, the makefile says WriteMyString.c , but your listings give that file's name as writemystring.c . Filenames in Linux are case-sensitive, so WriteMyString.c and writemystring.c would be two different files, whereas in DOS/Windows they'd be the same file.

    EDIT:
    Suggested order of trying out solutions:
    1. Verify that the source file names EXACTLY match their names in the directory; ie verify that none of the letters are of a different case.

    2. Make sure that LINK.c is properly defined.

    3. Try adding a dependency list.

    Remember the basic rule in troubleshooting: make one change at a time so that you can see the effects of each individual change.
    Last edited by dwise1_aol; July 3rd, 2003 at 10:24 AM.
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    OK, I got your makefile to work with a minimum of changes. The system I tested it on was the MinGW port of gcc and make to Windows 98 SE.

    Primarily, LINK.c was not defined, but make still refused to work even after I defined it. So here's what I did:

    1. I added the line:
    CC= gcc

    2. I changed all references to LINK.c to CC; ie, all instances of $(LINK.c) became $(CC).

    Here's the Makefile after the changes:
    Code:
    #
    # Makefile
    #
    
    SOURCES.c= main.c WriteMyString.c
    INCLUDES= header.h
    CFLAGS=
    SLIBS=
    PROGRAM= main
    CC= gcc
    
    OBJECTS= $(SOURCES.c:.c=.o)
    
    .KEEP_STATE:
    
    debug := CFLAGS= -g
    
    all debug: $(PROGRAM)
    
    $(PROGRAM): $(INCLUDES) $(OBJECTS)
            $(CC) -o $@ $(OBJECTS) $(SLIBS)
    
    clean:
            rm -f $(PROGRAM) $(OBJECTS)
    Please note that both of the lines:
    $(CC) -o $@ $(OBJECTS) $(SLIBS)
    rm -f $(PROGRAM) $(OBJECTS)
    MUST start with a tab character. Otherwise you will get a "missing separator" error. It MUST be a tab; spaces will not work.

    For general purpose, you should still verify that the case of the file names are correct.

    EDIT:
    I just tried it on my Red Hat 7 Linux system. The only change required was to start those two lines with a tab -- the tabs are probably present in your make file and their absence in my copy could simply be due to their having been stripped off by the web browser. Although no LINK.c shell variable existed, it had no problem substituting in cc for it. Now that has me puzzled.

    The possible mismatch of filenames remains the most likely cause of the problem and should still be checked. Please let me know what you find.
    Last edited by dwise1_aol; July 3rd, 2003 at 12:34 PM.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    india
    Posts
    28
    Rep Power
    0

    doubt in make file creation


    Hello
    it is telling

    make: Nothing to be done for `mymake'.
    what i want to do
  8. #5
  9. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222

    Re: doubt in make file creation


    Originally posted by suji
    Hello
    it is telling

    make: Nothing to be done for `mymake'.
    what i want to do
    I'm sorry, but I do not at all understand your reply.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    india
    Posts
    28
    Rep Power
    0

    reply to linux make


    Hello

    i just told about the error i got

    "make: Nothing to be done for `mymake'. "
  12. #7
  13. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222

    Re: reply to linux make


    Originally posted by suji
    Hello

    i just told about the error i got

    "make: Nothing to be done for `mymake'. "
    OK. That means that make didn't have to do anything.

    make compares the source files with the targets that depend on them. If a source file is more recent, then the targets are out of date and are re-created. The same thing happens if a target does not exist. If all the targets are more recent than the sources and all the targets exist (the .o files and the executable), then there is nothing to be done for that makefile.

    To force make to work, either delete the targets (eg, though make -fmymake clean) or touch the sources (eg, touch *.c *.h), which changes the file's modified time to the present, thus making it appear to have changed since the last make.

    I assume that you had solved your first problem by correcting the case in the WriteMyString.c filename.

IMN logo majestic logo threadwatch logo seochat tools logo