CUDA & Visual Studio 2008: Problems when trying to link different projects

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

keeping in mind that in this forum, 80% of the posted questions go unanswered I posted the same questions in StackOverflow
A very helpful person there not only bothered to help me 30minuted after I posted my question but he actually solved my problem!!!

here is the answered post:
http://stackoverflow.com/questions/5191813/cuda-visual-studio-2008-problems-when-trying-to-link-different-projects

I’m glad your problem got solved.

I don’t think that 80% of the questions going unanswered is an accurate statistical finding. But some of the forum regulars do not use Windows and may not even have any experience with Visual Studio. Your question would probably be better suited for the subforums dedicated to Windows specific questions.

Hello,

Let’s say someone needs cppIntegration in 2 different projects. In other words person A owns and builds the kernel project, but person B owns and builds the main project. In other words 2 different people are responsible for the main program, and device interface library.

How would it be done?

For example, I did a little experiment. The linker does not seem to find the device module’s binary when you comment out a line as follows. However the .o file is still on the disk so what else needs to be done for linking to be successful?

Add source files here

EXECUTABLE := cppIntegration

Cuda source files (compiled with cudacc)

The following line is commented out to simulate that I do not have the source code for the device module.

#CUFILES := cppIntegration.cu

The above line is commented out (see above).

C/C++ source files (compiled with gcc / c++)

CCFILES :=
main.cpp
cppIntegration_gold.cpp \

In many workplaces a module is a work assignment so they come from different people and on purpose we do not all have the same source code. Our hands are absolutely tied on this matter – as much as we would all like to have all the source code we do not.

Thank you for information!

(PS I am sorry to use another topic for this post. I did the best I could in finding a similar topic. I was unable to find a way to create a new topic. Sorry for my lack of forum usage knowledge. Please feel free to reclassify this post as appropriate. Thank you for your patience.)

The linux GCC command line compiler is being used in this case, not Windows. This means the successful make command at shell is the goal in this case. There is no IDE tool.

Thank you for information!

(PS I am sorry to use another topic for this post. I did the best I could in finding a similar topic. I was unable to find a way to create a new topic. Sorry for my lack of forum usage knowledge. Please feel free to reclassify this post as appropriate. Thank you for your patience.)

in order to make a new topic click the little icon on the top right of the thread table (little white page with green ‘+’)

this is not VS and Im afraid I dont know how to help you

Thank you sir!!