title: LNK2005, "already defined error" linker error in MSVC2010
body: <p>I am trying to implement a test project using the Point Cloud Library and OpenCV with multiple files. When I try to compile, I get the "already defined error" message. Probably I'm doing something stupid that cannot realize for some reason - I tried out a couple of solutions found here, none of them seemed to be help in my case.</p>
  
  <p>What I have:</p>
  
  <p>A libs.h file, where I load the lib files (in Project properties, I only set up the .lib paths and load the libs "by hand", like the headers):</p>
  
  <pre><code>#pragma once
  
  #ifndef PCLTEST_LIBS
  #define PCLTEST_LIBS
  
  #ifdef _DEBUG
    #pragma comment(lib, "pcl_apps-gd.lib")
    #pragma comment(lib, "pcl_common-gd.lib")
    // a bunch of other debug libs
  #else
    // the release libs
  #endif
  #endif
  </code></pre>
  
  <p>A main file from which I basically deleted everything at this point to debug:</p>
  
  <pre><code>// load the libs
  #ifndef PCLTEST_LIBS
  #include "libs.h"
  #endif
  
  // pcltest includes
  // if only this first one is #included, everything is OK
  #include "opencvOperations.h"
  // #including this one causes the error
  #include "files.h"
  // these ones are not working also
  //#include "cloudOperations.h"
  //#include "visualize.h"
  
  // c++ headers
  #include &lt;stdio.h&gt;
  #include &lt;string&gt;
  //#include &lt;sstream&gt;
  //#include &lt;iostream&gt;
  
  void writeInfo()
  {
      // some std::cout calls
  }
  
  int main( int argc, char* argv[] )
  {
      writeInfo();
      // this function is in opencvOperations.h and works OK
      pcltest::openLena();
  }
  </code></pre>
  
  <p>Then I get several error messages in my main.obj that some (PCL related) symbols are already defined in files.obj. I use PCL related calls both in opencvOperations and files, the first one is OK, the second one does not work.</p>
  
  <p><strong>Edit:</strong>
  To add more detail, my files.h header:</p>
  
  <pre><code>#pragma once
  
  #ifndef PCLTEST_FILES
  #define PCLTEST_FILES
  
  // pcl headers
  #ifndef PCL_COMMON_H_
  #include &lt;pcl/common/common_headers.h&gt;
  #endif
  #ifndef PCL_IO_FILE_IO_H_
  #include &lt;pcl/io/file_io.h&gt;
  #endif
  #ifndef PCL_IO_PCD_IO_H_ 
  #include &lt;pcl/io/pcd_io.h&gt;
  #endif
  #ifndef PCL_IO_PLY_IO_H_ 
  #include &lt;pcl/io/ply_io.h&gt;
  #endif
  // boost headers
  #ifndef BOOST_FILESYSTEM_OPERATIONSX_HPP 
  #include &lt;boost/filesystem/operations.hpp&gt;
  #endif
  
  #endif
  
  namespace pcltest
  {
      // function to open PCL or binary PLY files
      pcl::PointCloud&lt;pcl::PointXYZ&gt;::Ptr openCloud(std::string filename);
  
      // function to save the point cloud to PCD format
      void saveCloud();
  }
  </code></pre>
  
  <p>Before splitting the code into separate files, everything worked well (with the same project settings).</p>
  
  <p><strong>Edit2:</strong></p>
  
  <p>I located the source of the problem, </p>
  
  <pre><code>#include &lt;pcl/io/ply_io.h&gt;
  </code></pre>
  
  <p>causes this. For now, I got rid of everything related to PLY and everything works fine. I'll look at it later, this might be a PCL library specific issue. Still strange to me why this call causes linker error in an other file, where I don't even use PLY related functions/variables.</p>