using -j option with make - Unix

This is a discussion on using -j option with make - Unix ; Hi I an new to Unix. I ran into a problem while using the -j option with make command. The code complies fine when I do not use the -j option. However, when I use -j6 option, the compilation breaks. ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: using -j option with make

  1. using -j option with make

    Hi

    I an new to Unix. I ran into a problem while using the -j option with
    make command. The code complies fine when I do not use the -j option.
    However, when I use -j6 option, the compilation breaks. I surfed the
    net but could not find sufficient info on the usage of -j flag.

    Any pointers/references to the usage/limitations of -j flag on make
    will be highly appreciated.

    Regards
    Kumar
    sunilbadiger@yahoo.com


  2. Re: using -j option with make

    "kumar" writes:

    > I an new to Unix. I ran into a problem while using the -j option with
    > make command. The code complies fine when I do not use the -j option.
    > However, when I use -j6 option, the compilation breaks.


    This is usually the result of incorrectly written Makefile.

    > I surfed the
    > net but could not find sufficient info on the usage of -j flag.


    There isn't any because there is nothing to it (assuming correct
    Makefile) -- just add '-jN' to run N jobs in parallel.

    > Any pointers/references to the usage/limitations of -j flag on make
    > will be highly appreciated.


    You should be looking for references to writing correct Makefiles
    instead.

    You may get better advice if you tell us exactly *how* your build
    breaks. One common cause is building archive libraries "piecemeal",
    as in:

    $ cat Makefile
    LIB = libfoo.a(one.o) libfoo.a(two.o)
    all: $(LIB)
    $ touch one.c two.c && make -n
    cc -c -o one.o one.c
    ar rv libfoo.a one.o
    cc -c -o two.o two.c
    ar rv libfoo.a two.o
    rm one.o two.o

    The reason this will break when 'make -j6' is that parallel 'ar'
    jobs all "race" rewriting the same libfoo.a, and some of them "loose":
    their update is overwritten by another 'ar' job finishing just
    a bit later. The end result is that libfoo.a is missing some of
    the objects that should have been put into it, and subsequently
    any executable that needed these objects will fail to link.

    Here is one way to fix this particular problem:

    $ cat Makefile2
    LIB = libfoo.a
    OBJ = one.o two.o
    all: $(LIB)

    libfoo.a: $(OBJ)
    $(AR) ruv $@ $^

    $ make -n -f Makefile2
    cc -c -o one.o one.c
    cc -c -o two.o two.c
    ar ruv libfoo.a one.o two.o # no longer a race -- one job will build entire libfoo.a


    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

+ Reply to Thread