- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在处理我的第一个 CUDA 程序并使用 nvcc
编译器遇到错误,如果我使用 g++
编译则不会遇到这种错误。
我的代码:
#include <iostream>
#include <cmath>
using namespace std;
double distance(double first, double second);
int main(){
double dis;
dis = distance(7.0, 1.0);
cout << "distance = " << dis << endl;
return 0;
}
double distance(double first, double second){
double diff;
diff = abs(first-second);
return diff;
}
如果我用nvcc test.cu -o test
编译,结果是:
/usr/include/c++/5/bits/stl_iterator_base_types.h(168): error: name followed by "::" must be a class or namespace name
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
test.cu(11): here
/usr/include/c++/5/bits/stl_iterator_base_types.h(169): error: name followed by "::" must be a class or namespace name
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
test.cu(11): here
/usr/include/c++/5/bits/stl_iterator_base_types.h(170): error: name followed by "::" must be a class or namespace name
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
test.cu(11): here
/usr/include/c++/5/bits/stl_iterator_base_types.h(171): error: name followed by "::" must be a class or namespace name
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
test.cu(11): here
/usr/include/c++/5/bits/stl_iterator_base_types.h(172): error: name followed by "::" must be a class or namespace name
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
test.cu(11): here
当我将文件扩展名更改为.cpp 并按如下方式编译时,g++ test.cpp -o test
,代码符合要求。如果我然后执行 ./test
,我会得到我正在寻找的结果:
distance = 6
查看this帖子启发我考虑我从主机/设备划分的错误一侧调用某些东西的可能性,但是,我还没有进行任何 GPU 调用。
不确定发生了什么,但到目前为止,CUDA 编译器似乎非常挑剔。
最佳答案
您需要将 -std=c++11
选项添加到 nvcc 来编译它。通过使用 std 命名空间,您将与 std::distance
发生冲突,后者需要 c++11 或更高版本才能使用 nvcc 进行编译。
这个有效:
$ cat bugaboo.cu
#include <iostream>
#include <cmath>
using namespace std;
double distance(double first, double second);
int main(){
double dis;
dis = distance(7.0, 1.0);
cout << "distance = " << dis << endl;
return 0;
}
double distance(double first, double second){
double diff;
diff = abs(first-second);
return diff;
}
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Tue_Jun_12_23:07:04_CDT_2018
Cuda compilation tools, release 9.2, V9.2.148
$ nvcc --std=c++11 -o bugaboo bugaboo.cu
$ ./bugaboo
distance = 6
这不是:
$ nvcc -o bugaboo bugaboo.cu
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(165): error: a class or namespace qualified name is required
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
bugaboo.cu(10): here
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(165): error: global-scope qualifier (leading "::") is not allowed
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
bugaboo.cu(10): here
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(165): error: expected a ";"
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
bugaboo.cu(10): here
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(166): error: a class or namespace qualified name is required
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
bugaboo.cu(10): here
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(166): error: global-scope qualifier (leading "::") is not allowed
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
bugaboo.cu(10): here
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(166): error: expected a ";"
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
bugaboo.cu(10): here
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(167): error: a class or namespace qualified name is required
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
bugaboo.cu(10): here
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(167): error: global-scope qualifier (leading "::") is not allowed
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
bugaboo.cu(10): here
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(167): error: expected a ";"
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
bugaboo.cu(10): here
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(168): error: a class or namespace qualified name is required
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
bugaboo.cu(10): here
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(168): error: global-scope qualifier (leading "::") is not allowed
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
bugaboo.cu(10): here
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(168): error: expected a ";"
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
bugaboo.cu(10): here
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(169): error: a class or namespace qualified name is required
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
bugaboo.cu(10): here
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(169): error: global-scope qualifier (leading "::") is not allowed
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
bugaboo.cu(10): here
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(169): error: expected a ";"
detected during instantiation of class "std::iterator_traits<_Iterator> [with _Iterator=double]"
bugaboo.cu(10): here
15 errors detected in the compilation of "/tmp/tmpxft_00000acd_00000000-8_bugaboo.cpp1.ii".
关于c++ - CUDA 错误 : name followed by "::" must be a class or namespace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58224915/
大家好:我正在尝试创建一个命名空间,以便我可以在整个应用程序中的不同 CoffeeScript 文件中使用一个类(至少这是我对命名空间用途的理解) 我在这里找到了一个很好的例子:Classes wit
我想使用两个字符串(我不知道它们的内容)来创建两个 namespace 。如果 namespace 存在,我不想创建一个新的 namespace 。这是我的代码: function createNam
在 Struts 2 中,我看到根命名空间提供与根命名空间相同的行为,即充当“包罗万象”。我需要限制我的应用程序中的操作只能从一个 URL 访问,包括 URL 中没有 namespace 的操作。我的
我想在旧的代码库中包含新的 SASS。考虑到已经编写的新样式,我如何避免新样式泄漏。 例如 .box width: 100% // ... .tab display: inline-blo
我的\命名空间 \My\Namespace 那么,我应该使用哪一个,我看到了 php documentation主要使用 My\Namespace。 但据说 \My\Namespace 更好,因为没有
我正在研究 Rails 2.3.8。我的 environment.rb 中有以下内容 config.gem "redis" config.gem "redis-namespace", :lib =>
我有一个包含一些类型定义的小命名空间,我用它来使我的代码看起来更简洁。但是,我不想在每个使用这些类型之一的文件中添加“using namespace ...”行,毕竟我已经必须为文件添加 #inclu
如何获取 MediaWiki namespace 列表?最好有姓名和号码。 最佳答案 使用API:api.php?action=query&meta=siteinfo&siprop=namespa
为了使用“namespace import *”命令在不同的命名空间中使用该命名空间的变量/过程,“命名空间导出...”是否是必需的。我们真的应该在源命名空间中进行“导出”并在目标命名空间中进行“导入
假设我有以下 list ,例如部署,服务和入口。在默认 namespace 中,一切正常。虽然我想将资源投入到用manifest.yaml创建的另一个命名空间。我以为如果我写了 kubectl app
我想以编程方式将一个类从一个命名空间移动到另一个命名空间。这包括调整移动类在其先前命名空间中的任何依赖项。 我猜我可以以某种方式利用 Roslyn 项目,但我找不到起点。 编辑: 我正在尝试在 C#
Spring不同类型的注入方式 spring官网代码示例 1、不同类型的注入方式 <?xml version="1.0" encoding="UTF-8&qu
我想知道,考虑到这段代码: namespace A\B; use A\B as AB; use \Z\V as ZV; // another used namespace class Merry {
我正在研究一个似乎一切都很好的“董事会”类(class)。不知何故,在其他类(class)上工作了大约一个小时后,Board 在错误方面表现出一些非常奇怪的行为。 //headerfile #prag
我尝试在 TYPO3 扩展中创建多个 ViewHelper。 但是现在我尝试将 ViewHelper 放在子目录中,例如 扩展\类\ View 助手\自定义。 ViewHelper 的新
我的情况是:日历属于客户或销售员 因为我还有像 Event 和 File 这样的类,所以我将命名空间 App\Models 用于我所有的模型类。 所以我设置了多态关系: 在日历.php public
所有 Less 文档和教程都使用 #namespace > .mixin()当它进入命名空间时的语法。但是我发现自己更习惯于 .namespace.mixin()语法,即: .namespace()
我正在尝试使用 MS Robotics Studio 和 VS 2008 构建 DSS 服务,但是在构建时,我收到来自 dssproxy.exe 的错误消息: The class MyServ
例如,我们有两个用于解析简历的类,一个用于解析Excel,另一个用于解析HTML。我的同事们喜欢做的就是将这两个类命名为相同的名称,并将它们放在不同的命名空间中,如下所示: namespace XX.
我的库的所有类都在一个命名空间中定义。当我为 Doxygen 创建主页时,我必须在注释中明确使用这个命名空间来让 Doxygen 生成链接。我想对整个注释块使用“使用命名空间”之类的东西。 一个例子:
我是一名优秀的程序员,十分优秀!