【问题标题】:vs2015 cuda9.0 linked SHA1_Init with CUDA implement instead of openssl cpu libsvs2015 cuda9.0 将 SHA1_Init 与 CUDA 实现链接,而不是 openssl cpu 库
【发布时间】:2019-05-19 02:01:12
【问题描述】:

我是 cuda、c++ 的初学者,我正在尝试将 openssl sha1 cpu 代码移动到 cuda c,但我遇到了一个奇怪的问题。

这是可以重现问题的最少代码。 这个vs2015 cuda9.0项目一共有三个文件。它们是 main.cpp 、sha1.cu 和 sha1.h

//main.cpp
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include "openssl\sha.h"
int main()
{
    SHA_CTX ctx;
    SHA1_Init(&ctx);
    return 0;
}

//sha1.h
#ifndef SHA1_H
#define SHA1_H
#include <stdint.h>
#include <cuda_runtime.h>
namespace cudatest {
#ifdef __cplusplus
extern "C" {
#endif
        typedef struct
        {
            uint32_t state[5];
            uint32_t count[2];
            unsigned char buffer[64];
        } SHA1_CTX;
#define SHA_CTX SHA1_CTX
#define SHA_DIGEST_LENGTH 20
        __device__  void SHA1_Init(SHA1_CTX * context);
#ifdef __cplusplus
    }
#endif
}
#endif /* SHA1_H */


//sha1.cu
#include <cuda_runtime.h>
#include "sha1.h"
namespace cudatest {
    __device__ void SHA1_Init(SHA1_CTX * context)
    {

    }
}

main.cpp使用C/C++编译器,sha1.cu使用CUDA C/C++

我将 openssl 头文件添加到 AdditionalIncludeDirectories,将包含 ssleay32.lib 和 libeay32.lib 的目录设置为库路径,使用 ssleay32.lib、libeay32.lib 设置 AdditionalDependencies。

然后项目构建没有错误也没有警告。但是当我运行它时 或调试它,我发现函数 SHA1_Init 运行到设备代码中并且 程序立即崩溃。

为什么编译器将函数 SHA1_Init 与 cuda 设备相关联 SHA1_Init 实现了一个命名空间 cudatest ssleay32.lib、libeay32.lib CPU 的实现?

【问题讨论】:

    标签: c++ visual-studio cuda openssl


    【解决方案1】:

    好的,我找到了问题。我不应该在 c++ 命名空间中使用 extern "C"。它使函数对全局命名空间可见。如果你在 .cpp 文件中定义了另一个 c SHA1_Init 函数,链接器会报错。但是如果另一个 SHA1_Init 在 openssl 库中,vs C/C++ 链接器除了链接到 cuda 实现之外什么也没发出警告。

    【讨论】:

      猜你喜欢
      • 2016-08-19
      • 1970-01-01
      • 2014-07-18
      • 2011-10-22
      • 2019-02-18
      • 2012-09-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-09
      相关资源
      最近更新 更多