Recently, I compile a simple c++ file:
main.cpp: #include
int main() {
std::cout << “this is a test \n” << std::endl;
float4 a = make_float4(1.0, 2.33, 4.5, 6.5);
}
if I use the command “nvcc -o main main.cpp -x=cu”, I succeeding in compile main.cpp and the output is right.
But I use a CMakeLists.txt for compiling it and I fail in compiling it.
the CMakeLists.txt is as follow:
And the errors are as follow:
main.cpp: In function ‘int main()’:
main.cpp:4:1: error: ‘float4’ was not declared in this scope
float4 a = make_float4(1.0, 2.33, 4.5, 6.5);
^
main.cpp:6:14: error: ‘a’ was not declared in this scope
std::cout << a.x << a.y << a.z << a.w << std::endl;
Thank you very much. I add #include<vector_types.h> in my cpp files, but I failed in compiled it. the error is as follow:
/home/manifold/CUDA_Test1/test1/main.cpp: In function ‘int main()’:
/home/manifold/CUDA_Test1/test1/main.cpp:5:43: error: ‘make_float4’ was not declared in this scope
float4 a = make_float4(1.0, 2.33, 4.5, 6.5);
^
CMakeFiles/test_cuda_project.dir/build.make:62: recipe for target ‘CMakeFiles/test_cuda_project.dir/main.cpp.o’ failed
make[2]: *** [CMakeFiles/test_cuda_project.dir/main.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/test_cuda_project.dir/all’ failed
make[1]: *** [CMakeFiles/test_cuda_project.dir/all] Error 2
Makefile:83: recipe for target ‘all’ failed
make: *** [all] Error 2
I can use command “nvcc -o main main.cpp -x=cu” to succeed compile cpp files with float4 types. But I cann’t use CMakeLists.txt to compiles it. This is really confusing.
Note that CUDA’s float4 type is a struct with additional alignment requirements. Substituting a one-off local struct in the manner shown in #4 may or may not make a difference (e.g. on performance).
in ubuntu16.04, using “nvcc -o main main.cpp -x=cu” can succeed in compiling it, but cmake cann’t.
I think ‘set(CUDA_NVCC_FLAGS … -x=cu)’ this command don’t work. My version is CMake 3.5.1. I think Cmake has something wrong with -x=cu?