问题描述
我正在尝试将 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 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!