jjzjj

c++ - VS2012 提示 "already defined"类尽管 pragma once

coder 2024-02-25 原文

我对我的项目有点不知所措。语言是 C++,编辑器 Visual Studio 2012,一旦完成它应该是一个光线转换渲染器(光线转换位仍然缺失)。 为此,我正在使用数学库 Eigen。但是,当我尝试构建时出现链接错误。我过去没有太多使用 C++ 语言,对这个错误所做的研究对我没有帮助。

这是编译器的输出:

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 ==========

错误来自 3 个类,这是它们的标题:

#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;
};

如您所见,所有类上都有“pragma once”,Eigen 类都由 ifndef/define/endif 保护。

我收集到的是,这可能是由于我的代码是由不同的 TU 编译的,其中分别包含 Eigen,因此出现了所有“已定义”的错误。但我不知道如何纠正这个问题(我不能使用 extern,因为我使用我的类 TransformedObject 作为其他类的成员)。

提前致谢

最佳答案

正在复制 user3073879(提交者)评论:

问题已解决,我从包含声明相机的主机函数的文件中删除了所有 CUDA 代码。(这是一个测试函数)。这意味着它确实是 NVCC 的问题

将此问题标记为已回答。

关于c++ - VS2012 提示 "already defined"类尽管 pragma once,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20421384/

有关c++ - VS2012 提示 "already defined"类尽管 pragma once的更多相关文章

  1. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby-on-rails - Railstutorial : db:populate vs. 工厂女孩 - 2

    在railstutorial中,作者为什么选择使用这个(代码list10.25):http://ruby.railstutorial.org/chapters/updating-showing-and-deleting-usersnamespace:dbdodesc"Filldatabasewithsampledata"task:populate=>:environmentdoRake::Task['db:reset'].invokeUser.create!(:name=>"ExampleUser",:email=>"example@railstutorial.org",:passwo

  4. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  5. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

  6. ruby-on-rails - 迷你测试错误 : "NameError: uninitialized constant" - 2

    我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test

  7. ruby-on-rails - 相关表上的范围为 "WHERE ... LIKE" - 2

    我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que

  8. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

  9. ruby - 安装 Ruby 时遇到问题(无法下载资源 "readline--patch") - 2

    当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub

  10. ruby - RVM "ERROR: Unable to checkout branch ."单用户 - 2

    我在新的Debian6VirtualBoxVM上安装RVM时遇到问题。我已经安装了所有需要的包并使用下载了安装脚本(curl-shttps://rvm.beginrescueend.com/install/rvm)>rvm,但以单个用户身份运行时bashrvm我收到以下错误消息:ERROR:Unabletocheckoutbranch.安装在这里停止,并且(据我所知)没有安装RVM的任何文件。如果我以root身份运行脚本(对于多用户安装),我会收到另一条消息:Successfullycheckedoutbranch''安装程序继续并指示成功,但未添加.rvm目录,甚至在修改我的.bas

随机推荐