Dear all,
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’
For the sake of people that may see this post here are some of the better ones:
http://forums.nvidia.com/index.php?showtopic=100283&view=findpost&p=594469
http://www.programmerfish.com/how-to-run-cuda-on-visual-studio-2008-vs08/
http://gamelab.epitech.eu/blogtech/?p=13 (quite good)
http://stackoverflow.com/questions/2046228/how-do-i-start-a-new-cuda-project-in-visual-studio-2008 (very good)
But what is missing here?
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.
What do I want/need?
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.
I’ve looked everywhere to no avail, nobody seems to be using multiple projects.
My problem is:
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
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)
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->stub_function();
return 0;
}
CUDA Project:
testCuda.h
#include <cstdio>
#include <cstdlib>
#include <iostream>
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<< a <<"\n";
}
test.cu
#include "cuda.h"
extern "C" int cuda_function()
{
return 5;
}
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)
http://dl.dropbox.com/u/3091507/CUDA.zip
I would terribly appreciate any information or advice that can help me solve this conundrum
Thanks a lot Adam