albertxavier001/gnuplot-cpp

Multiple definition

Closed this issue · 6 comments

There is a problem in your gnuplot_i.hpp. In particular you incur in a
multiple definition problem in linking phase if you
1. create two or more .h / .cpp file where you include and use the library
2. this two or more file are part of a single project (executable)
3. compile, you get the multiple definition error

Why it occurs?

Because in the .hpp you use normal function definition instead than only
inline function definitions. Moreover some variables are duplicated in the
linking phase (the part under // initialize static data) and the functions
after (
//------------------------------------------------------------------------------
//
// define static member function: set Gnuplot path manual
//   for windows: path with slash '/' not backslash '\'
//
)

A trivial solution consist in cut and paste these two section and save them
in a separate .cpp file.


Original issue reported on code.google.com by malloble...@gmail.com on 11 Oct 2009 at 4:13

Attachments:

Thanks for that, I encountered the same problem. Your code works for me.

Original comment by praffens...@gmail.com on 16 Dec 2009 at 12:51

[deleted comment]
I noticed that in your version the functions plot_x, plot_xy, plot_xy_err and 
plot_xyz are still in the include file. 
Will this not give the same multiple definition problems? Why not move these 
functions to the cc-file as well or at 
least make them inlines?

Original comment by bloch....@googlemail.com on 13 Apr 2010 at 9:27

Same for me, thanks !

Original comment by langejos...@gmail.com on 20 Jul 2013 at 5:59

Everything now works..thanks!

Original comment by rachmawa...@gmail.com on 20 Aug 2014 at 8:14

Original comment by ettl.mar...@gmail.com on 23 Aug 2014 at 7:57

  • Changed state: Fixed