当包含来自CUDA 10.0的npps.h时发生链接错误

问题描述 投票:3回答:1

我正在编写一个C ++应用程序,它将使用CUDA在GPU上进行一些信号处理。因为我正在执行信号处理,所以我包含了npps.h,其中包含CUDA信号处理功能。但是,每次包含npps.h时,我都会遇到链接错误。通过创建如下所示的1行文件,我能够复制该问题。

CuTest.cpp

#include <npps.h>

我尝试使用以下命令进行构建:

g++ -I/tools/cuda-10.0/include -L/tools/cuda-10.0/lib64  -lnpps -c CuTest.cpp

[当我尝试构建时,出现以下错误。

In file included from /tools/cuda-10.0/include/cuda_runtime.h:95:0,
                 from /tools/cuda-10.0/include/nppdefs.h:52,
                 from /tools/cuda-10.0/include/npps.h:60,
                 from CuTest.cpp:2:
/tools/cuda-10.0/include/channel_descriptor.h:104:1: error: template with C linkage
 template<class T> __inline__ __host__ cudaChannelFormatDesc cudaCreateChannelDesc(void)
 ^
/tools/cuda-10.0/include/channel_descriptor.h:137:1: error: template specialization with C linkage
 template<> __inline__ __host__ cudaChannelFormatDesc cudaCreateChannelDesc<char>(void)

这是npps.h的样子:

#ifndef NV_NPPS_H
#define NV_NPPS_H

/**
* \file npps.h
* NPP Signal Processing Functionality.
*/

#ifdef __cplusplus
extern "C" {
#endif

#include "nppdefs.h"

/** @defgroup npps NPP Signal Processing
*
* @{
*
*/

#include "npps_support_functions.h"
#include "npps_initialization.h"
#include "npps_conversion_functions.h"
#include "npps_arithmetic_and_logical_operations.h"
#include "npps_statistics_functions.h"
#include "npps_filtering_functions.h"

/** @} end of Signal Processing module */

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* NV_NPPS_H */

从错误中我可以看到,包装在extern“ C”中的npps.h文件中的一个文件最终包含一个带有模板代码的文件,该文件在extern“ C”内部为“ no-no”。从错误中我看到有问题的文件是cuda_runtime.h。因此,我将CuTest.cpp修改为如下所示。

CuTest.cpp:

#include <cuda_runtime.h>
#include <npps.h>

首先通过包含cuda_runtime.h,由于包含保护,它将不再被npps.h包含,因此当包含它时,它将不会被包装在外部“ C”中。这适用于CuTest.cpp,并且在较大的应用程序中执行相同的操作,因此它也可以生成和运行。

这是我正在运行的配置

g++ (GCC) 8.1.0
CUDA 10.0
CentOS Linux release 7.6.1810 (Core)

注意:我在g ++ 4.8.1中得到相同的行为

这是CUDA标头中的错误吗?还有其他人看到或能够复制它吗?

c++ linux cuda g++
1个回答
0
投票

您需要在npps.h文件的#include "nppdefs.h"行之前声明#ifdef __cplusplus

#ifndef NV_NPPS_H
#define NV_NPPS_H

#include "nppdefs.h"

#ifdef __cplusplus
extern "C" {
#endif
...
© www.soinside.com 2019 - 2024. All rights reserved.