Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) Duplicate symbol

 

Compile error.

 

 

 

 

 

Full error message

 

ld: duplicate symbol Gnuplot::SetLineStyles() in /MyFolder/UnitGnuplotInterface.o and /MyFolder/GnuplotInterfaceMain.o

 

 

 

 

 

Cause

 

IDE: Xcode 3.1.2

Compiler: Gcc 4.0.1

 

This might happen if you use my Gnuplot Interface. The cause is in the following lines:

 

//Yes, this #include is non-standard
//But it enables you to compile-and-run
//To do it correctly, add the file 'Gnuplot.cpp' to your project,
//and #include 'Gnuplot.h' instead.
#include "UnitGnuplotInterface.cpp"

 

 

 

 

 

 

Solution

 

Duplicate symbols occur when you have both added an implementation file (.cpp) to your project and #included it. This way, the implementation file (.cpp) gets compiled twice: once as a module in your project (as it is added to your project) and subsequently as a piece of #included code.

 

Avoid #including implementation files (.cpp). Prefer #including header files (.h) only. Prefer adding implementation files (.cpp) to your project.

 

For the Gnuplot Interface problem: follow the hints from the commments:

 

//#include "UnitGnuplotInterface.cpp" //Already added to project
#include "UnitGnuplotInterface.h"

 

 

 

 

 

Acknowledgements

 

Thanks to Roger Wehage for sending me a complete and detailed email with this problem

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict