title: CUDA & Visual Studio 2008: Problems when trying to link different projects
body: <p>While scouring the net for an answer to my problem I have seen multiple forum and blog posts tackling the 'How do I set up, compile, link and run a CUDA project in VIsual Studio 2008'</p>
  
  <p>(I was trying to give the links but I am not allowed to, as a new poster :p)</p>
  
  <p><strong>But what is missing here?</strong></p>
  
  <p>What's missing is that all the above guides or posts tell you how to set up a single VS project which will be the startup project and will run by itself. As a consequence they are using the 'CUDA Runtime API Rule' which is tailored to create a CUDA friendly .exe file.</p>
  
  <p><strong>What do I want/need?</strong></p>
  
  <p>1)I want to have a VS solution which will contain multiple projects, most of which are written in C++. There will be one main project written in C++ creating the '.exe' (containing the 'main' function and therefore controlling the flow) and multiple other projects that will be creating appropriate '.lib' files against which the main project will link.
  2)In the simplest form I need one project which will be doing CUDA stuff which will create the lib file and the main project which will link to it and use it.</p>
  
  <p>I've looked everywhere to no avail, nobody seems to be using multiple projects.</p>
  
  <p><strong>My problem is:</strong>
  1)The CUDA project creates a lib and therefore must use the 'CUDA Driver API Rule' and not the runtime variant (if I dare do so then the CUDA project tries to use libraries used by the main one and there are multiply defined projects'
  2)When trying to do it the proper way the main project cant link to the CUDA project</p>
  
  <p>Here is the example code I am using to show what the deal is (I will also attach the VS sln file here for those of you who want to try it out)</p>
  
  <pre><code>Outline:
      VS Solution
          Main Project(C++ project producing the .exe and containing the main function)
              main.cpp
  
                  #include "../CUDAProject/testCuda.h"
  
                  int
                  main(int argc, char** argv)
                  {
  
                      testCudaClass* t2;
                      t2 = new testCudaClass();
                      t2-&gt;stub_function();
  
                      return 0;
                  }
  
          CUDA Project:
              testCuda.h
  
                  #include &lt;cstdio&gt;
                  #include &lt;cstdlib&gt;
                  #include &lt;iostream&gt;
  
                  class testCudaClass
                  {
                  public:
                      void stub_function();
                  };
  
              testCuda.cpp
  
                  #include "testCuda.h"
                  extern "C" int cuda_function();
  
                  void testCudaClass::stub_function()
                  {
                      int a;
                      a=cuda_function();
                      std::cout&lt;&lt; a &lt;&lt;"\n";
                  }
  
              test.cu
  
                  #include "cuda.h"
  
                  extern "C" int cuda_function()
                  {
                      return 5;
                  }           
  </code></pre>
  
  <p>Attached (temporary dropbox public links) is a zip file with 2 VS2008 solutions, one where I have a single CUDA project which works fine and one where I try to do the above (part of the project's code is outlined above)</p>
  
  <p><a href="http://dl.dropbox.com/u/3091507/CUDA.zip" rel="nofollow">http://dl.dropbox.com/u/3091507/CUDA.zip</a></p>
  
  <p><strong>I would terribly appreciate any information or advice that can help me solve this conundrum</strong></p>
  
  <p>Thanks a lot
  Adam</p>