Why does nvcc fails to compile a CUDA file with boost::spirit?(为什么 nvcc 无法使用 boost::spirit 编译 CUDA 文件?)
问题描述
我正在尝试将 CUDA 集成到使用 boost::spirit 的现有应用程序中.
I'm trying to integrate CUDA to an existing aplication wich uses boost::spirit.
隔离问题,我发现以下代码不能与 nvcc copile:
Isolating the problem, I've found out that the following code does not copile with nvcc:
main.cu:
#include <boost/spirit/include/qi.hpp>
int main(){
exit(0);
}
使用 nvcc -o cudaTest main.cu 编译我得到了很多可以看到的错误 这里.
Compiling with nvcc -o cudaTest main.cu I get a lot of errors that can be seen here.
但是如果我将文件名更改为 main.cpp,然后使用 nvcc 再次编译,它就可以工作了.这里发生了什么,我该如何解决?
But if I change the filename to main.cpp, and compile again using nvcc, it works. What is happening here and how can I fix it?
推荐答案
nvcc 有时在编译 Boost 等复杂模板代码时会遇到麻烦,即使该代码仅在 中使用__host__ 函数.
nvcc sometimes has trouble compiling complex template code such as is found in Boost, even if the code is only used in __host__ functions.
当文件的扩展名是 .cpp 时,nvcc 不会自行解析,而是将代码转发到主机编译器,这就是为什么您会观察到不同的行为,具体取决于文件扩展名.
When a file's extension is .cpp, nvcc performs no parsing itself and instead forwards the code to the host compiler, which is why you observe different behavior depending on the file extension.
如果可能,尝试将依赖于 Boost 的代码隔离到不需要被 nvcc 解析的 .cpp 文件中.
If possible, try to quarantine code which depends on Boost into .cpp files which needn't be parsed by nvcc.
我还要确保尝试使用最近的 nvcc">CUDA 4.1.nvcc 的模板支持随着每个版本的发布而改进.
I'd also make sure to try the nvcc which ships with the recent CUDA 4.1. nvcc's template support improves with each release.
这篇关于为什么 nvcc 无法使用 boost::spirit 编译 CUDA 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 nvcc 无法使用 boost::spirit 编译 CUDA 文件?
基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- CString 到 char* 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
