我想要一个 .cuh
文件,我也可以在其中声明内核函数和主机函数。这些函数的实现将在 .cu
文件内进行。该实现将包括使用 Thrust
库。
在 main.cpp
文件中,我想使用 .cu
文件内的实现。假设我们有这样的东西:
myFunctions.cuh
#include <thrust/sort.h>
#include <thrust/device_vector.h>
#include <thrust/remove.h>
#include <thrust/host_vector.h>
#include <iostream>
__host__ void show();
myFunctions.cu
#include "myFunctions.cuh"
__host__ void show(){
std::cout<<"test"<<std::endl;
}
main.cpp
#include "myFunctions.cuh"
int main(void){
show();
return 0;
}
如果我这样做进行编译:
nvcc myFunctions.cu main.cpp -O3
然后输入 ./a.out
运行可执行文件
将打印测试
文本。
但是,如果我决定使用以下命令包含 -std=c++0x
:
nvcc myFunctions.cu main.cpp -O3 --compiler-options "-std=c++0x"
我收到很多错误,其中一些错误如下:
/usr/include/c++/4.6/x86_64-linux-gnu/./bits/c++config.h(159): error: identifier "nullptr" is undefined
/usr/include/c++/4.6/x86_64-linux-gnu/./bits/c++config.h(159): error: expected a ";"
/usr/include/c++/4.6/bits/exception_ptr.h(93): error: incomplete type is not allowed
/usr/include/c++/4.6/bits/exception_ptr.h(93): error: expected a ";"
/usr/include/c++/4.6/bits/exception_ptr.h(112): error: expected a ")"
/usr/include/c++/4.6/bits/exception_ptr.h(114): error: expected a ">"
/usr/include/c++/4.6/bits/exception_ptr.h(114): error: identifier "__o" is undefined
这些错误意味着什么以及如何避免它们?
提前谢谢
最佳答案
如果你看this specific answer ,您会看到用户正在使用您正在使用的相同开关编译一个空的虚拟应用程序,并收到一些完全相同的错误。如果您将该开关的使用限制为编译 .cpp 文件,您可能会得到更好的结果:
myFunctions.h:
void show();
myFunctions.cu:
#include <thrust/sort.h>
#include <thrust/device_vector.h>
#include <thrust/remove.h>
#include <thrust/host_vector.h>
#include <thrust/sequence.h>
#include <iostream>
#include "myFunctions.h"
void show(){
thrust::device_vector<int> my_ints(10);
thrust::sequence(my_ints.begin(), my_ints.end());
std::cout<<"my_ints[9] = "<< my_ints[9] << std::endl;
}
main.cpp:
#include "myFunctions.h"
int main(void){
show();
return 0;
}
构建:
g++ -c -std=c++0x main.cpp
nvcc -arch=sm_20 -c myFunctions.cu
g++ -L/usr/local/cuda/lib64 -lcudart -o test main.o myFunctions.o
关于c++11 - CUDA 和 Thrust 库 : Trouble with using . cuh .cu 和 .cpp 文件以及 -std=c++0x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16149538/