<html><body><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:10pt"><div><span>I am not familiar with VTK smart pointers, but this seems like a standard C/C++ issue,&nbsp; not a VTK one. A header file gets basically merged into the C file and if you have multiple C files including your header you will end up with multiple instances of the variable. What you want to do instead is define "extern vtkSmartPointer&lt;vtkDoubleArray&gt; X;" in the header file, and then perform the actual allocation in your main(). Also make sure you don't inadvertently end up including the header twice, this is best accomplished by wrapping the entire header by <br></span></div><div><span>#ifndef __some_name</span></div><div><span>#define __some_name</span></div><div>.. your header here ..</div><div><br></div><div>#endif<br><span></span></div><div><br></div>  <div style="font-family: arial, helvetica, sans-serif; font-size:
 10pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr"> <font face="Arial" size="2"> <hr size="1">  <b><span style="font-weight:bold;">From:</span></b> cel02000 &lt;cel02000@yahoo.com&gt;<br> <b><span style="font-weight: bold;">To:</span></b> vtkusers@vtk.org <br> <b><span style="font-weight: bold;">Sent:</span></b> Tuesday, June 5, 2012 3:02 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> [vtkusers] defining a global vtk object<br> </font> </div> <br>
Dear All,<br><br>How should I define a global vtkDoubleArray? In the header file, I declared:<br>vtkSmartPointer&lt;vtkDoubleArray&gt; X = vtkDoubleArray::New();<br>I have a function in mycode.cpp which configures X during run-time. However,<br>the linker does not like it and give me the following error:<br>1&gt;main.obj : error LNK2005: "class vtkSmartPointer&lt;class vtkDoubleArray&gt; X"<br>(?X@@3V?$vtkSmartPointer@VvtkDoubleArray@@@@A) already defined in mycode.obj<br><br>Could someone help me?<br>Thanks,<br><br>--<br>View this message in context: http://vtk.1045678.n5.nabble.com/defining-a-global-vtk-object-tp5713602.html<br>Sent from the VTK - Users mailing list archive at <a target="_blank" href="http://nabble.com/">Nabble.com</a>.<br>_______________________________________________<br>Powered by <a target="_blank" href="http://www.kitware.com/">www.kitware.com</a><br><br>Visit other Kitware open-source projects at
 http://www.kitware.com/opensource/opensource.html<br><br>Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ<br><br>Follow this link to subscribe/unsubscribe:<br>http://www.vtk.org/mailman/listinfo/vtkusers<br><br><br> </div> </div>  </div></body></html>