1

When I compile the following code containing the design C++11, I get errors - it does not compile. I've tried with different flags, but I haven't found a solution.

My setting: CUDA 6.5, gcc 4.4.7 I am not able to change the settings. How can I still make this work?

#include <stdio.h>
#include <vector>
#include "KD_tree.h"
#include "KD_tree.cpp"
#include <iostream>
#include <algorithm>
#include <cmath>
#include <future>
#define MYDEVICE 0

using namespace std;


int main()
{
    //do something..... 

    cudaDeviceProp devProp;
    cudaGetDeviceProperties(&devProp, MYDEVICE);
    printDevProp(devProp);
    int max_threads = devProp.warpSize;

   //do something else ... 

    return 0;
}

I've tried compiling with different flags:

nvcc -std=c++11 cudaMain.cu KD_tree.cpp -arch=sm_20 -o tree.out
In file included from cudaMain.cu:14:
simple_kd_tree.h:12:19: warning: extra tokens at end of #include directive
cudaMain.cu:19:18: error: future: No such file or directory


nvcc --std=c++11 cudaMain.cu KD_tree.cpp -arch=sm_20 -o tree.out
In file included from cudaMain.cu:14:
simple_kd_tree.h:12:19: warning: extra tokens at end of #include directive
cudaMain.cu:19:18: error: future: No such file or directory


nvcc --std=c++11 cudaMain.cu KD_tree.cpp -arch=sm_20 -c -o tree.out
nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified

Do I have to split the c++ part? How would I do this exactly?

3
  • 1
    #include "KD_tree.cpp" in cudaMain.cu and adding KD_tree.cpp to the compile command line is almost certainly not what you want to do. If you can compile KD_tree.cpp successfully with your existing g++, then you may have good results by removing the c++11 features (i.e. <future>) from cudaMain.cu, and compile (-c) cudaMain.cu with nvcc, and compile (-c) KD_tree.cpp with g++, and then link the two objects together. There are many example questions demonstrating this here on the cuda tag. Jun 3, 2015 at 14:14
  • Thanks Robert! I will do it like this as soon, as I've got more kernels going on. I believe with the above code it might be possible to change cudaMain.cu into cudaMain.cpp and compile the whole thing with gcc 4.8 ? I've been trying this for some time now but get undefined reference to cudaGetDeviceProperties'as an error. Do you know what I have to put as a flag? I've #include "cuda.h" #include "cuda_runtime.h"`.
    – aces
    Jun 3, 2015 at 17:19
  • I've found the solution: g++ -std=gnu++11 -L/usr/local/cuda/lib64 -lcudart -I/usr/local/cuda/include main.cpp KD_tree.hpp -lstdc++ -pthread -o test.out -L/usr/local/cuda/lib -lcudart -lcuda for anyone with a similar problem.
    – aces
    Jun 3, 2015 at 18:52

1 Answer 1

5

C++11 support is added officially in CUDA 7.0. And you need GCC version 4.7 or later to have C++11 support. See details here: http://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-compiler-new-features

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.