Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>Solution 1</h2> <p>You can't pass <code>-c</code> in your linking phase, as that will tell the compiler to skip linking.</p> <p>Your problem is</p> <pre><code>$(BIN): $(OBJ) $(CXX) $(LINKOBJ) -o "calculPi.exe" </code></pre> <p>with</p> <pre><code>CXX_FLAGS =-g -c -lpthread -lm </code></pre> <p>where <code>$(CXX)</code> expands to <code>gcc -g -c -lpthread -lm ...</code></p> <p>get rid of the <code>-c</code> there.</p> <p>Only pass -c when compiling from source to object modules.</p> <h2>Solution 2</h2> <p>Re the second problem, you aren't actually defining the variables anywhere. In your <code>.c</code> file you need the lines:</p> <pre><code>Coord* production; int indice_prod; int indice_cons; </code></pre> <p>(Assuming you really want global variables). This will fix the unresolved external error. You can't write to them until they've been allocated!</p> <h2>Notes</h2> <p>Also note that you can specify how to build object files from source in one rule:</p> <pre><code>.c.o: $(CC) $(CFLAGS) -c $&lt; </code></pre> <p>and specify the dependencies without rules:</p> <pre><code>main.o: main.c approx.o: approx.c approx.h producteur.o: producteur.c producteur.h sequentialApproximation.o : sequentialApproximation.c sequentialApproximation.h </code></pre> <p>etc.</p> <h2>Other notes.</h2> <p>Also, as general rule of thumb, <code>CXX</code> should only contain the compiler name, no flags. Those should go in <code>CXX_FLAGS</code>. And why are you calling it <code>CXX</code> not <code>CC</code>? Use <code>g++</code> if you want a C++ compiler, or use <code>CC</code>. Since you have <code>.c</code> files, I'll assume C. So in your case, you should change:</p> <pre><code>CXX_FLAGS =-g -c -lpthread -lm CXX = gcc $(CXX_FLAGS) $(INCL) $(DEFS) </code></pre> <p>to</p> <pre><code>CC = gcc CFLAGS = -g -lpthread -lm $(INCL) $(DEFS) # also removed -c </code></pre> <p>And you don't need a separate <code>LINK_CXX</code>.</p> <h2>Sample Makefile</h2> <p>So a minimal Makefile should look like:</p> <pre><code># Makefile CC = gcc # compiler/linker frontend INCL = -I$(INCL_DIR) # includes DEFS = -D_DEBUG_ # defines CFLAGS = -g $(INCL) $(DEFS) # compiler flags LFLAGS = -lpthread -lm -g # linker flags OBJ = approx.o producteur.o sequentialApproximation.o main.o BIN = calculPi.exe all: $(BIN) $(BIN): $(OBJ) $(CC) $(LFLAGS) -o$@ $^ main.o: main.c approx.o: approx.c approx.h producteur.o: producteur.c producteur.h sequentialApproximation.o : sequentialApproximation.c sequentialApproximation.h .c.o: $(CC) $(CFLAGS) -c $&lt; # clean and other stuff. </code></pre>
 

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