Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ multiple definition in Linux
    text
    copied!<p>When I make these files, g++ occurs two errors which are multiple definition and previous definition. </p> <p>Makefile:</p> <pre><code>INCLUDE = -I/usr/X11R6/include/ LIBDIR = -L/usr/X11R6/lib FLAGS = -Wall CC = g++ CFLAGS = $(FLAGS) $(INCLUDE) LIBS = -lglut -lGL -lGLU glTestDemo.o: glTestDemo.cpp headers.h $(CC) $(CFLAGS) -c glTestDemo.cpp display.o: display.cpp headers.h $(CC) $(CLFAGS) -c display.cpp glTestDemo: glTestDemo.o display.o $(CC) $(CFLAGS) glTestDemo.o display.o -o $@ $(LIBDIR) $&lt; $(LIBS) # The initial white space is a tab all: glTestDemo clean: rm glTestDemo *.o </code></pre> <p>headers.h</p> <pre><code>#ifndef __HEADERS_H__ #define __HEADERS_H__ #include &lt;GL/glut.h&gt; extern int NumPoints; extern void incorrect_display (void); #endif </code></pre> <p>display.cpp</p> <pre><code>#include "headers.h" void incorrect_display (void) { glClear (GL_COLOR_BUFFER_BIT); glPointSize (1.0); glDrawArrays (GL_POINTS, 0, NumPoints); glFlush (); } </code></pre> <p>glTestDemo.cpp</p> <pre><code>#include "headers.h" int NumPoints = 5000; int main (int argc, char** argv) { glutInit (&amp;argc, argv); glutInitDisplayMode (GLUT_RGBA); glutInitWindowPosition (50, 50); glutInitWindowSize (600, 600); glutCreateWindow ("Test title"); glutDisplayFunc (incorrect_display); glutMainLoop (); return 0; } </code></pre> <p>The error message like that after I type make all :</p> <pre><code>/usr/bin/ld: error: glTestDemo.o: multiple definition of 'NumPoints' /usr/bin/ld: glTestDemo.o: previous definition here /usr/bin/ld: error: glTestDemo.o: multiple definition of 'main' /usr/bin/ld: glTestDemo.o: previous definition here collect2: error: ld returned 1 exit status make: *** [glTestDemo] Error 1 </code></pre> <p>I have make a shell script to test my c++ syntax and g++ flag and openGL flag, which is used by linking. It is success. Hence, I think it is the Makefile cause the error. But I can not find the problem for this. </p>
 

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