CUDA& Visual Studio 2008:尝试链接不同的项目时出现问题 [英] CUDA & Visual Studio 2008: Problems when trying to link different projects

查看:224
本文介绍了CUDA& Visual Studio 2008:尝试链接不同的项目时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然在网上寻找答案解决我的问题,我看到多个论坛和博客帖子处理如何在VIsual Studio 2008中设置,编译,链接和运行CUDA项目



(我试图提供链接,但我不允许,作为一个新的海报:p)





缺少的是所有上述指南或帖子告诉您如何设置一个VS项目将是启动项目,将自己运行。因此,他们正在使用CUDA运行时API规则,这是专为创建一个CUDA友好的.exe文件。



我想要/需要什么?



1)我想要一个VS解决方案,它将包含多个项目,其中大部分是用C ++编写的。将有一个主要项目用C ++编写,创建'.exe'(包含'main'函数,因此控制流程)和多个其他项目,将创建相应的'.lib'文件,主项目将链接到该文件。
2)在最简单的形式中,我需要一个项目,它将会创建lib文件和主要项目,它将链接到它并使用它CUDA的东西。



我已经无处不在,没有人可以使用多个项目。



我的问题是:
1)CUDA项目创建一个lib,因此必须使用CUDA驱动程序API规则而不是运行时变体(如果我敢这样做,那么CUDA项目会尝试使用主库使用的库,并且有多个定义的项目'
2)当试图做正确的方式主要项目无法链接到CUDA项目



这里是我使用的示例代码显示什么

 大纲:


VS解决方案
主项目(生成.exe并包含main函数的C ++项目)
main.cpp

#include../CUDAProject/testCuda。 h

int
main(int argc,char ** argv)
{

testCudaClass * t2;
t2 = new testCudaClass();
t2-> stub_function();

return 0;
}

CUDA项目:
testCuda.h

#include< cstdio>
#include< cstdlib>
#include< iostream>

class testCudaClass
{
public:
void stub_function();
};

testCuda.cpp

#includetestCuda.h
externCint cuda_function();

void testCudaClass :: stub_function()
{
int a;
a = cuda_function();
std :: cout<< a<<\ n;
}

test.cu

#includecuda.h

externCint cuda_function()
{
return 5;
}

附加(临时Dropbox公共链接)是一个带有2个VS2008解决方案的zip文件,一个其中我有一个单一的CUDA项目工作正常和一个我尝试做上述(项目代码的一部分如上所述)



http://dl.dropbox.com/u/3091507/CUDA.zip



我非常感谢能够帮助我解决这个难题的任何信息或建议




Adam

解决方案

我检查了你的代码,这是我成功编译并运行它: p>


  • 使用CUDA运行时API(即使您有多个项目也可以使用)


  • 主项目 - >配置属性 - >链接器 - >常规 - >附加库目录:添加到CUDA库的路径(它是CUDA安装路径的子文件夹之一)

  • MainProject - >配置属性 - >链接器 - >输入 - >附加依赖关系:添加cudart.lib


  • MainProject - >配置属性 - >链接器 - >输入 - >忽略特定库:添加LIBCMT以删除有关冲突的警告。


  • 确保您对正常的.cpp和.cu使用相同的运行时库。在你的情况下,它不匹配,似乎这是警告在图书馆不兼容的原因。比较以下值:




    • C / C ++ - >代码生成 - >运行库


    • CUDA运行时API - >主机 - >运行时库





此外,你生成testCppProject.lib和CUDAProject.lib,但你包括test.lib& CUDAProject.lib,其中第一个是lib的一些旧版本。


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 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.

这篇关于CUDA&amp; Visual Studio 2008:尝试链接不同的项目时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆