开发者

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

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'

(I was trying to give the links but I am not allowed to, as a new poster :p)

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开发者_JS百科 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


I checked your code and this is what I did to succesfully compile it and run it:

  • Used CUDA Runtime API (it is OK to use it even if you have multiple projects)

  • MainProject -> Configuration Properties -> Linker -> General -> Additional Library Directories : added path to CUDA libs (it's one of subfolders of your CUDA installation path)

  • MainProject -> Configuration Properties -> Linker -> Input -> Additional Dependencies : added "cudart.lib"

  • MainProject -> Configuration Properties -> Linker -> Input -> Ignore Specific Library : added "LIBCMT" to remove that warning about conflicts.

  • Make sure that you use the same "Runtime Library" for normal .cpp and .cu. In your case it didn't match and it seems it was the reason for the warning abount library incompatibility. Compare the values of :

    • C/C++ -> Code Generation -> Runtime Library

    • CUDA Runtime API -> Host -> Runtime Library

Also, you are generating "testCppProject.lib" and "CUDAProject.lib", but you are including "test.lib" & "CUDAProject.lib", where the first one is some older version of the lib.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜