A Problem with makefile.

Discussion in 'C Programming' started by prasadjoshi124@gmail.com, Nov 29, 2006.

  1. Guest

    Hi All,

    I am trying to write a make file with the following specifications.

    [Prasad@rsharma dir_make]$ pwd
    /home/Prasad/programs/c/lsp/dir_make

    [Prasad@rsharma dir_make]$ ls
    add include main.c Makefile sub

    Now, here main.c uses a function present in add/add.c and sub/sub.c.

    I have written this makefile

    [Prasad@rsharma dir_make]$ cat Makefile
    SUB_DIRS := add sub
    all:
    @for d in $(SUB_DIRS) ; do \
    ( \
    cd $$d ; \
    make ; \
    ) \
    done
    OBJ_FILES=$($(foreach dir,$(SUB_DIRS),$(wildcard $(dir)/*.o)))
    echo $(OBJ_FILES)
    gcc main.c -o main -I $$PWD/include $(OBJ_FILES)

    clean:
    OBJ_FILES=$($(foreach dir,$(SUB_DIRS),$(wildcard $(dir)/*.o)))
    echo $(OBJ_FILES)
    rm $(OBJ_FILES)

    But, it does not seem to work properly. I am getting following error
    ==>

    [Prasad@rsharma dir_make]$ make
    make[1]: Entering directory `/home/Prasad/programs/c/lsp/dir_make/add'
    make[1]: `add.o' is up to date.
    make[1]: Leaving directory `/home/Prasad/programs/c/lsp/dir_make/add'
    make[1]: Entering directory `/home/Prasad/programs/c/lsp/dir_make/sub'
    make[1]: `sub.o' is up to date.
    make[1]: Leaving directory `/home/Prasad/programs/c/lsp/dir_make/sub'
    OBJ_FILES=
    echo

    gcc main.c -o main -I $PWD/include
    /tmp/ccmR5Xy4.o: In function `main':main.c:(.text+0x21): undefined
    reference to `add'
    :main.c:(.text+0x45): undefined reference to `sub'
    collect2: ld returned 1 exit status
    make: *** [all] Error 1

    It seems that OBJ_FILES variable is not getting set properly.

    Please help.

    Thanks and regards,
    Prasad.
    , Nov 29, 2006
    #1
    1. Advertising

  2. santosh Guest

    wrote:
    > Hi All,
    >
    > I am trying to write a make file with the following specifications.

    <snip>
    > It seems that OBJ_FILES variable is not getting set properly.
    >
    > Please help.


    Ask in comp.unix.programmer or comp.os.ms-windows.programmer, (if that
    is your development platform). But, really, the GNU docs for make are
    quite excellent. Read them through.
    santosh, Nov 29, 2006
    #2
    1. Advertising

  3. In article <>,
    <> wrote:

    >I am trying to write a make file with the following specifications.


    makefiles are artifacts of your particular development environment,
    and are not part of C itself. You need to ask in a newsgroup that
    supports your development environment.


    >[Prasad@rsharma dir_make]$ cat Makefile


    > OBJ_FILES=$($(foreach dir,$(SUB_DIRS),$(wildcard $(dir)/*.o)))
    > echo $(OBJ_FILES)
    > gcc main.c -o main -I $$PWD/include $(OBJ_FILES)


    I've never seen a foreach in a makefile before, nor any mention
    of 'wildcard'. That, together with the gcc line, suggests to me that
    you are *not* using make, but instead are using gmake . If so,
    then one of the gnu.* newsgroups would be appropriate.
    --
    Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
    Walter Roberson, Nov 29, 2006
    #3
  4. CBFalconer Guest

    wrote:
    >
    > I am trying to write a make file with the following specifications.
    >

    .... snip ...
    >
    > Please help.


    Why should we, when you posted a completely off-topic query. Try a
    newsgroup where make and makefiles are topical, such as
    comp.unix.programmer, or something with gcc or gnu in its name.
    Next time find out what is and is not topical on a newsgroup before
    posting.

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>
    CBFalconer, Nov 29, 2006
    #4
    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,140
  2. John Abel
    Replies:
    0
    Views:
    295
    John Abel
    Sep 29, 2003
  3. fabio

    problem with a makefile

    fabio, Mar 9, 2006, in forum: C Programming
    Replies:
    4
    Views:
    384
    fabio
    Mar 10, 2006
  4. dolphin

    what is the problem about my makefile

    dolphin, Apr 16, 2007, in forum: C Programming
    Replies:
    6
    Views:
    356
    Kenny McCormack
    Apr 16, 2007
  5. problem in makefile

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

Share This Page