what is the problem about my makefile

Discussion in 'C Programming' started by dolphin, Apr 16, 2007.

  1. dolphin

    dolphin Guest

    Hi! I am learing makefile recently.Now I have a problem.
    I write a very simple program just like "hello world"
    I write two makefile for it.One is included in another.
    the first is makefile
    include mainmake.mk
    example:main.o
    cc -o example main.o
    clean:
    rm -f *.o

    this is the second makefile named mainmake.mk which is included in
    makefile.
    main.o:main.c head.h
    cc -c -g main.c

    when I type make command in shell.Only main.o file is created.The file
    main did not be created.What is the problem?I am in redhat 9.0
    dolphin, Apr 16, 2007
    #1
    1. Advertising

  2. On Apr 16, 10:53 am, "dolphin" <> wrote:
    > Hi! I am learing makefile recently.Now I have a problem.
    > I write a very simple program just like "hello world"
    > I write two makefile for it.


    The program we can help you with. The makefile aspect is
    off topic.

    --
    Peter
    Peter Nilsson, Apr 16, 2007
    #2
    1. Advertising

  3. dolphin

    R Smith Guest

    "dolphin" <> wrote in news:1176684813.213582.98550
    @l77g2000hsb.googlegroups.com:

    > Hi! I am learing makefile recently.Now I have a problem.
    > I write a very simple program just like "hello world"
    > I write two makefile for it.One is included in another.
    > the first is makefile
    > include mainmake.mk
    > example:main.o
    > cc -o example main.o
    > clean:
    > rm -f *.o
    >
    > this is the second makefile named mainmake.mk which is included in
    > makefile.
    > main.o:main.c head.h
    > cc -c -g main.c
    >
    > when I type make command in shell.Only main.o file is created.The file
    > main did not be created.What is the problem?I am in redhat 9.0
    >
    >


    Off topic, off schmopic, who cares? You need help.

    Try this:

    cc -o example main.c

    You can't compile a .o file. You can say I want to compile a .c program
    and call it this (-o).
    R Smith, Apr 16, 2007
    #3
  4. dolphin

    CBFalconer Guest

    dolphin wrote:
    >
    > Hi! I am learing makefile recently.Now I have a problem.
    > I write a very simple program just like "hello world"
    > I write two makefile for it.One is included in another.
    > the first is makefile
    >
    > include mainmake.mk
    > example:main.o
    > cc -o example main.o
    > clean:
    > rm -f *.o
    >
    > this is the second makefile named mainmake.mk which is included in
    > makefile.
    > main.o:main.c head.h
    > cc -c -g main.c
    >
    > when I type make command in shell.Only main.o file is created.The file
    > main did not be created.What is the problem?I am in redhat 9.0


    That creates main.o, which will be the relocatable object version
    of your c file. To create the runnable final file you need to
    execute:

    cc -o main main.o

    which you express (in the make file) as:

    main : main.o #the dependency
    cc -o main main.o #the command to execute

    Note that the commands have a leading tab char.

    --
    <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
    <http://www.securityfocus.com/columnists/423>
    <http://www.aaxnet.com/editor/edit043.html>

    "A man who is right every time is not likely to do very much."
    -- Francis Crick, co-discover of DNA
    "There is nothing more amazing than stupidity in action."
    -- Thomas Matthews



    --
    Posted via a free Usenet account from http://www.teranews.com
    CBFalconer, Apr 16, 2007
    #4
  5. dolphin

    Bill Pursell Guest

    On Apr 16, 1:53 am, "dolphin" <> wrote:

    > I write a very simple program just like "hello world"
    > I write two makefile for it.One is included in another.
    > the first is makefile
    > include mainmake.mk
    > example:main.o
    > cc -o example main.o


    This is off-topic here, but if you
    insert your included makefile by hand,
    you'll see that invoking make with no
    arguments is equivalent to invoking:
    "make main.o" since main.o is the
    first target. Try moving the include
    line below the example target.
    Bill Pursell, Apr 16, 2007
    #5
  6. dolphin

    Chris Torek Guest

    >"dolphin" <> wrote in news:1176684813.213582.98550
    >@l77g2000hsb.googlegroups.com:
    >> Hi! I am learing makefile recently. ...

    [makefile snipped]
    >> when I type make command in shell. Only main.o file is created. The file
    >> main did not be created. What is the problem? I am in redhat 9.0


    You want comp.unix.programmer, or a linux-specific newsgroup (although
    the former will suffice here).

    In article <Xns9913E4458BC79rhsmith52comcastnet@216.196.97.131>,
    R Smith <> wrote:
    >Off topic, off schmopic, who cares? You need help.


    Well, "dolphin" may care, since you have given him an incorrect
    answer. :)

    >Try this:
    >
    >cc -o example main.c


    Although that can be made to work, it is not what he should be
    doing in this case.

    >You can't compile a .o file.


    Depending on the system, you *can*, depending on just what one
    means by "compile" ... and RedHat Linux is one of those where you
    can, and he has done the right things to make the given .o file
    "compile-able".

    For more information, try comp.unix.programmer.
    --
    In-Real-Life: Chris Torek, Wind River Systems
    Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
    email: forget about it http://web.torek.net/torek/index.html
    Reading email is like searching for food in the garbage, thanks to spammers.
    Chris Torek, Apr 16, 2007
    #6
  7. In article <>,
    Chris Torek <> wrote:
    ....
    >>You can't compile a .o file.

    >
    >Depending on the system, you *can*, depending on just what one
    >means by "compile" ... and RedHat Linux is one of those where you
    >can, and he has done the right things to make the given .o file
    >"compile-able".


    I think the statement "You can't compile a .o file." is technically
    true, but moot. It is much akin to the statement that you can't bake a
    cake. This last is true, since at the point in time when it is baking,
    it is not a cake, but merely a bunch of ingredients mixed together in a
    pan. Only when the baking is finished, is it a cake.

    But I think most of us would agree that both statements are pretty silly
    (though I daresy they might well appeal to the idiots^Wpedants in this ng)
    Kenny McCormack, Apr 16, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    16
    Views:
    1,139
  2. John Abel
    Replies:
    0
    Views:
    294
    John Abel
    Sep 29, 2003
  3. fabio

    problem with a makefile

    fabio, Mar 9, 2006, in forum: C Programming
    Replies:
    4
    Views:
    383
    fabio
    Mar 10, 2006
  4. A Problem with makefile.

    , Nov 29, 2006, in forum: C Programming
    Replies:
    3
    Views:
    296
    CBFalconer
    Nov 29, 2006
  5. problem in makefile

    , Jun 18, 2007, in forum: C Programming
    Replies:
    9
    Views:
    1,358
    CBFalconer
    Jun 18, 2007
Loading...

Share This Page