title: How to compile thrust and c++ project?
body: <p>I got big problems about the compile when I want to use thrust and c++ meanwhile.</p>
  
  <p>Here is the project structure(just a test project):</p>
  
  <p><strong>sortbase.h</strong></p>
  
  <pre><code>#include&lt;iostream&gt;
  #include &lt;thrust/device_vector.h&gt;
  using namespace std;
  
  template&lt;class T&gt;
  class SortBase
  {
  public:
          void Init()
          {
          }
          void resize(const int &amp;x)
          {
                  CV.resize(x);
                  cout&lt;&lt;"resize succeed!"&lt;&lt;endl;
          }
  private: 
          thrust::device_vector&lt;T&gt; CV;
  };
  </code></pre>
  
  <p><strong>sorter.h</strong></p>
  
  <pre><code>#ifndef __SORTER_H__
  #define __SORTER_H__
  #include &lt;iostream&gt;
  #include &lt;thrust/device_vector.h&gt;
  #include "sortbase.h"
  using namespace std;
  
  template&lt;class T&gt;
  void ttest()
  {cout&lt;&lt;"tttttttttttttttt";cout&lt;&lt;endl;}
          template&lt;class KEY&gt;
          class Sorter
          {
          public:
                  Sorter():CV(NULL)
                  {
                          CV=new SortBase&lt;KEY&gt;();
                  }
                  ~Sorter()
                  {
                          if (CV!=NULL)
                          {
                                  delete CV;
                                  CV=NULL;
                          }
                  }
                  __host__ __device__
                  virtual bool operator()(const KEY&amp; x,const KEY&amp; y)const
                  {
                          return (x&lt;y);
                  }
                  void test()
                  {
                          //ttest&lt;KEY&gt;();
                          resize(5);
                  }
          private:
                  void resize(const int &amp;x)
                  {
                          CV-&gt;resize(x);
                          cout&lt;&lt;"resize: "&lt;&lt;x&lt;&lt;endl;
                  }
          private:
                  SortBase&lt;KEY&gt; *CV;
          };
  
  #endif
  </code></pre>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "include/sorter.cu"
  using namespace std;
  
  int main(int argc,char **argv)
  {
          Sorter&lt;int&gt; *sorter=new Sorter&lt;int&gt;();
          sorter-&gt;test();
          return 0;
  }
  </code></pre>
  
  <p>What I do like this:</p>
  
  <pre><code>nvcc -c sorter.cu
  g++ -c main.cpp -I/usr/local/cuda/include
  g++ sorter.o main.o -o sorter
  </code></pre>
  
  <p>but the second step gives the error message, a lot of warning and error message.
  who can help me?
  some warning and error message like these:</p>
  
  <pre><code>/usr/local/cuda/include/thrust/detail/device/cuda/for_each.inl: In function \u2018RandomAccessIterator thrust::detail::device::cuda::for_each_n(RandomAccessIterator, Size, UnaryFunction) [with RandomAccessIterator = thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;int&gt; &gt;, Size = long unsigned int, UnaryFunction = thrust::detail::generate_functor&lt;thrust::detail::fill_functor&lt;int&gt; &gt;]\u2019:
  /usr/local/cuda/include/thrust/detail/device/dispatch/for_each.h:56:   instantiated from \u2018RandomAccessIterator thrust::detail::device::dispatch::for_each_n(RandomAccessIterator, Size, UnaryFunction, thrust::detail::cuda_device_space_tag) [with RandomAccessIterator = thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;int&gt; &gt;, Size = long unsigned int, UnaryFunction = thrust::detail::generate_functor&lt;thrust::detail::fill_functor&lt;int&gt; &gt;]\u2019
  /usr/local/cuda/include/thrust/detail/device/for_each.inl:43:   instantiated from \u2018OutputIterator thrust::detail::device::for_each_n(OutputIterator, Size, UnaryFunction) [with OutputIterator = thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;int&gt; &gt;, Size = long unsigned int, UnaryFunction = thrust::detail::generate_functor&lt;thrust::detail::fill_functor&lt;int&gt; &gt;]\u2019
  /usr/local/cuda/include/thrust/detail/dispatch/for_each.h:84:   instantiated from \u2018OutputIterator thrust::detail::dispatch::for_each_n(OutputIterator, Size, UnaryFunction, thrust::device_space_tag) [with OutputIterator = thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;int&gt; &gt;, Size = long unsigned int, UnaryFunction = thrust::detail::generate_functor&lt;thrust::detail::fill_functor&lt;int&gt; &gt;]\u2019
  /usr/local/cuda/include/thrust/detail/for_each.inl:41:   instantiated from \u2018OutputIterator thrust::detail::for_each_n(OutputIterator, Size, UnaryFunction) [with OutputIterator = thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;int&gt; &gt;, Size = long unsigned int, UnaryFunction = thrust::detail::generate_functor&lt;thrust::detail::fill_functor&lt;int&gt; &gt;]\u2019
  /usr/local/cuda/include/thrust/detail/generate.inl:47:   instantiated from \u2018OutputIterator thrust::generate_n(OutputIterator, Size, Generator) [with OutputIterator = thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;int&gt; &gt;, Size = long unsigned int, Generator = thrust::detail::fill_functor&lt;int&gt;]\u2019
  /usr/local/cuda/include/thrust/detail/device/cuda/fill.inl:87:   instantiated from \u2018OutputIterator thrust::detail::device::cuda::detail::fill_n(OutputIterator, Size, const T&amp;, thrust::detail::false_type) [with OutputIterator = thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;int&gt; &gt;, Size = long unsigned int, T = int]\u2019
  /usr/local/cuda/include/thrust/detail/device/cuda/fill.inl:117:   instantiated from \u2018OutputIterator thrust::detail::device::cuda::detail::fill_n(OutputIterator, Size, const T&amp;, thrust::detail::true_type) [with OutputIterator = thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;int&gt; &gt;, Size = long unsigned int, T = int]\u2019
  /usr/local/cuda/include/thrust/detail/device/cuda/fill.inl:138:   instantiated from \u2018OutputIterator thrust::detail::device::cuda::fill_n(OutputIterator, Size, const T&amp;) [with OutputIterator = thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;int&gt; &gt;, Size = long unsigned int, T = int]\u2019
  /usr/local/cuda/include/thrust/detail/device/dispatch/fill.h:57:   instantiated from \u2018OutputIterator thrust::detail::device::dispatch::fill_n(OutputIterator, Size, const T&amp;, thrust::detail::cuda_device_space_tag) [with OutputIterator = thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;int&gt; &gt;, Size = long unsigned int, T = int]\u2019
  /usr/local/cuda/include/thrust/detail/device/fill.inl:47:   instantiated from \u2018OutputIterator thrust::detail::device::fill_n(OutputIterator, Size, const T&amp;) [with OutputIterator = thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;int&gt; &gt;, Size = long unsigned int, T = int]\u2019
  /usr/local/cuda/include/thrust/detail/dispatch/fill.h:76:   instantiated from \u2018OutputIterator thrust::detail::dispatch::fill_n(OutputIterator, Size, const T&amp;, thrust::device_space_tag) [with OutputIterator = thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;int&gt; &gt;, Size = long unsigned int, T = int]\u2019
  /usr/local/cuda/include/thrust/detail/fill.inl:46:   instantiated from \u2018OutputIterator thrust::fill_n(OutputIterator, Size, const T&amp;) [with OutputIterator = thrust::detail::normal_iterator&lt;thrust::device_ptr&lt;int&gt; &gt;, Size = long unsigned int, T = int]\u2019
  /usr/local/cuda/include/thrust/detail/vector_base.inl:757:   instantiated from \u2018void thrust::detail::vector_base&lt;T, Alloc&gt;::fill_insert(typename thrust::detail::contiguous_storage&lt;T, Alloc&gt;::iterator, typename thrust::detail::contiguous_storage&lt;T, Alloc&gt;::size_type, const T&amp;) [with T = int, Alloc = thrust::device_malloc_allocator&lt;int&gt;]\u2019
  /usr/local/cuda/include/thrust/detail/vector_base.inl:561:   instantiated from \u2018void thrust::detail::vector_base&lt;T, Alloc&gt;::insert(typename thrust::detail::contiguous_storage&lt;T, Alloc&gt;::iterator, typename thrust::detail::contiguous_storage&lt;T, Alloc&gt;::size_type, const T&amp;) [with T = int, Alloc = thrust::device_malloc_allocator&lt;int&gt;]\u2019
  /usr/local/cuda/include/thrust/detail/vector_base.inl:223:   instantiated from \u2018void thrust::detail::vector_base&lt;T, Alloc&gt;::resize(typename thrust::detail::contiguous_storage&lt;T, Alloc&gt;::size_type, typename thrust::detail::contiguous_storage&lt;T, Alloc&gt;::value_type) [with T = int, Alloc = thrust::device_malloc_allocator&lt;int&gt;]\u2019
  
  include/sortbase.h:14:   instantiated from void SortBase&lt;T&gt;::resize(const int&amp;) [with T = int]
  include/sorter.cu:40:   instantiated from void Sorter&lt;KEY&gt;::resize(const int&amp;) [with KEY = int]
  include/sorter.cu:35:   instantiated from void Sorter&lt;KEY&gt;::test() [with KEY = int]
  main.cpp:9:   instantiated from here
  /usr/local/cuda/include/thrust/detail/device/cuda/for_each.inl:93: error: invalid     application of sizeof to incomplete type thrust::detail::STATIC_ASSERTION_FAILURE&lt;false&gt;
  /usr/local/cuda/include/thrust/detail/device/cuda/arch.h: At global scope:
  /usr/local/cuda/include/thrust/detail/device/cuda/arch.h:59: warning: inline function size_t thrust::detail::device::cuda::arch::compute_capability() used but never defined
  </code></pre>