VS2012 complaining about "already defined" classes despite pragma once

Viewed 1059

I am having a bit of a quandary on my project. The language is C++, the editor Visual Studio 2012, and it is supposed to be a ray casting renderer once it will be finished (the ray casting bits are still missing). For this, I am using the math library Eigen. However, I get linking errors when I try to build. I have not used the C++ language much in the past, and the research done on this error has not helped me.

Here is the output from the compiler:

1>------ Build started: Project: TX52-3DStereo-RT-CUDA, Configuration: Debug x64 ------
1>Build started 06/12/2013 10:55:56.
1>InitializeBuildStatus:
1>  Touching "x64\Debug\TX52-3DStereo-RT-CUDA.unsuccessfulbuild".
1>AddCudaCompilePropsDeps:
1>Skipping target "AddCudaCompilePropsDeps" because all output files are up-to-date with respect to the input files.
1>CudaBuild:
1>  Compiling CUDA source file kernel.cu...
1>  
1>  C:\Users\Satanikas\Documents\Visual Studio 2012\Projects\TX52-3DStereo-RT-CUDA\TX52-3DStereo-RT-CUDA>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2012 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include"  -G   --keep-dir x64\Debug -maxrregcount=0  --machine 64 --compile -cudart static  -g   -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o x64\Debug\kernel.cu.obj "C:\Users\Satanikas\Documents\Visual Studio 2012\Projects\TX52-3DStereo-RT-CUDA\TX52-3DStereo-RT-CUDA\kernel.cu" 
1>c:\users\satanikas\documents\visual studio 2012\common\inc\eigen\src/Core/arch/SSE/PacketMath.h(169): warning : controlling expression is constant
1>  
1>c:\users\satanikas\documents\visual studio 2012\common\inc\eigen\src/Core/Block.h(102): error : "operator=" has already been declared in the current scope
1>            detected during instantiation of class "Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel> [with XprType=VectorType, BlockRows=<expression>, BlockCols=<expression>, InnerPanel=false]" 
1>  c:\users\satanikas\documents\visual studio 2012\common\inc\eigen\src/Core/VectorBlock.h(58): here
1>  
1>c:\users\satanikas\documents\visual studio 2012\common\inc\eigen\src/Core/Ref.h(122): error : "operator=" has already been declared in the current scope
1>            detected during instantiation of class "Eigen::RefBase<Derived> [with Derived=Eigen::Ref<PlainObjectType, Options, StrideType>]" 
1>  (183): here
1>  
1>c:\users\satanikas\documents\visual studio 2012\common\inc\eigen\src/Core/products/Parallelizer.h(20): warning : variable "m_maxThreads" was set but never used
1>  
1>c:\users\satanikas\documents\visual studio 2012\common\inc\eigen\src/Geometry/RotationBase.h(76): error : function template "Eigen::operator*(const Eigen::EigenBase<OtherDerived> &, const Eigen::Quaternion<_Scalar, _Options> &)" has already been defined
1>            detected during:
1>              instantiation of class "Eigen::RotationBase<Derived, _Dim> [with Derived=Eigen::Quaternion<_Scalar, _Options>, _Dim=3]" 
1>  c:\users\satanikas\documents\visual studio 2012\common\inc\eigen\src/Geometry/Quaternion.h(35): here
1>              instantiation of class "Eigen::QuaternionBase<Derived> [with Derived=Eigen::Quaternion<_Scalar, _Options>]" 
1>  c:\users\satanikas\documents\visual studio 2012\common\inc\eigen\src/Geometry/Quaternion.h(236): here
1>  
1>  3 errors detected in the compilation of "C:/Users/SATANI~1/AppData/Local/Temp/tmpxft_000010c8_00000000-5_kernel.cpp1.ii".
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\BuildCustomizations\CUDA 5.5.targets(592,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2012 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include"  -G   --keep-dir x64\Debug -maxrregcount=0  --machine 64 --compile -cudart static  -g   -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o x64\Debug\kernel.cu.obj "C:\Users\Satanikas\Documents\Visual Studio 2012\Projects\TX52-3DStereo-RT-CUDA\TX52-3DStereo-RT-CUDA\kernel.cu"" exited with code 2.
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:03.40
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The errors come from 3 classes, here are their headers:

#pragma once

#include <Eigen\Geometry>

class TransformedObject
{
public:
    TransformedObject(void);
    ~TransformedObject(void);

    void rotate(const Eigen::Quaternionf&);
    void setRotation(const Eigen::Quaternionf&);
    void translate(const Eigen::Vector3f&);
    void setTranslation(const Eigen::Vector3f&);
    void scale(const float&);
    const Eigen::Matrix4f getMatrix(void);

    Eigen::Transform<float, 3, Eigen::Affine> transform;
};


#pragma once

#include "TransformedObject.h"

class Camera
{
public:
    Camera(void);
    ~Camera(void);
    void computeRays();
    void setFOV(float angle);
    void setResolution(int w, int h);
private:
    TransformedObject transformation;
    float fov;
    unsigned int width;
    unsigned int height;
    float* raysDirections;
    Eigen::Vector3f raysOrigin;
};


#pragma once

#include <forward_list>
#include "TransformedObject.h"

class ScenegraphNode
{
public:
    ScenegraphNode(void);
    ~ScenegraphNode(void);
private:
    TransformedObject transformation;
    size_t sceneHash;
    std::forward_list<ScenegraphNode*> children;

    int countVertices() const;
};

As you can see, there are "pragma once" on all classes, and Eigen classes are all guarded by ifndef/define/endif.

What I gathered was that it was possibly due to my code being compiled by different TU, which included Eigen separately, hence all the "already defined" errors. But I have no idea how to correct this (I can't use extern since I use my class TransformedObject as a member of other classes).

Thanks in advance,

1 Answers
Related