Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First problem:</p> <pre><code>COMP = compose ${COMP}.o: ... </code></pre> <p>Adding a suffix to a variable isn't quite that simple in Make. And in this case you have some whitespace problems, which is why you're getting the warning messages, and why you couldn't build <code>compose</code> even if you tried.</p> <p>Since you're a beginner, let's take a simple approach, crude but effective. We'll rewrite those rules, and add one at the top so that you can build both files with <code>make</code>:</p> <pre><code>all: alphamask compose alphamask: alphamask.o ${CC} ${LFLAGS} -o alphamask alphamask.o ${LDFLAGS} alphamask.o: alphamask.cpp ${CC} ${CFLAGS} -c alphamask.cpp compose: compose.o ${CC} ${LFLAGS} -o compose compose.o ${LDFLAGS} compose.o: compose.cpp ${CC} ${CFLAGS} -c compose.cpp </code></pre> <p>After you've got this working perfectly, a lot of improvements are possible.</p> <p><b>EDIT:</b></p> <p>Now that it's working perfectly, we can improve it. First let's put in automatic variables, to reduce the redundancy: <code>$@</code> is the name of the target, <code>$^</code> is the prerequisites, and <code>$&lt;</code> is the first prerequisite.</p> <pre><code>all: alphamask compose alphamask: alphamask.o ${CC} ${LFLAGS} -o $@ $^ ${LDFLAGS} alphamask.o: alphamask.cpp ${CC} ${CFLAGS} -c $&lt; compose: compose.o ${CC} ${LFLAGS} -o $@ $^ ${LDFLAGS} compose.o: compose.cpp ${CC} ${CFLAGS} -c $&lt; </code></pre> <p>Now we see redundancy in the commands, so we can combine the rules:</p> <pre><code>all: alphamask compose alphamask: alphamask.o compose: compose.o alphamask compose: ${CC} ${LFLAGS} -o $@ $^ ${LDFLAGS} alphamask.o: alphamask.cpp compose.o: compose.cpp alphamask.o compose.o: ${CC} ${CFLAGS} -c $&lt; </code></pre> <p>Now we can replace the object (<code>.o</code>) rules with a pattern rule:</p> <pre><code>all: alphamask compose alphamask: alphamask.o compose: compose.o alphamask compose: ${CC} ${LFLAGS} -o $@ $^ ${LDFLAGS} %.o: %.cpp ${CC} ${CFLAGS} -c $&lt; </code></pre> <p>And a static pattern rule for the executables. (We could use a pattern rule for these too, but that would be a little too general.)</p> <pre><code>EXECUTABLES = alphamask compose .PHONY: all all: $(EXECUTABLES) $(EXECUTABLES): % : %.o ${CC} ${LFLAGS} -o $@ $^ ${LDFLAGS} %.o: %.cpp ${CC} ${CFLAGS} -c $&lt; </code></pre> <p>When you make these improvements, <b>get each improvement working perfectly before you advance to the next.</b></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload