我的C代码赢了';t根据“.cu”文件中的C代码编译 我有2个文件,从我以前的程序(用BC++编写的C++)编写了一个小的CUDA库。p>

我的C代码赢了';t根据“.cu”文件中的C代码编译 我有2个文件,从我以前的程序(用BC++编写的C++)编写了一个小的CUDA库。p>,cuda,Cuda,此库的标题为: #ifndef __cudaLU__ #define __cudaLU__ #include <assert.h> #include <cuda_runtime.h> #include <cusolverDn.h> #include <cusolverSp.h> #include <cusparse.h> #include <cuCo

此库的标题为:

     #ifndef __cudaLU__
     #define __cudaLU__

     #include <assert.h>
     #include <cuda_runtime.h>
     #include <cusolverDn.h>
     #include <cusolverSp.h>
     #include <cusparse.h>
     #include <cuComplex.h>
     #include <stdlib.h>


     void denseLS(int dim,
                  std::complex<float> * A,
                  std::complex<float> * b );

     void sparseLS(int dim,
                    std::complex<float> *csrVal,
                    int *csrRowPtr,
                    int *csrColInd,
                    std::complex<float> *vecVal);

     #endif
它失败了,出现了一系列类似的错误。其中很少有:

     ..NA/cudaLS.cu(115): error: namespace "std" has no member "complex"

     ..NA/cudaLS.cu(115): error: expected a ")"

     ..NA/cudaLS.cu(137): error: identifier "csrRowPtr" is undefined

     ..NA/cudaLS.cu(169): error: identifier "csrColInd" is undefined

     ..NA/cudaLS.cu(170): error: identifier "csrVal" is undefined

     ..NA/cudaLS.cu(171): error: identifier "vecVal" is undefined
我试图改变std::complex->float complex,但什么都不起作用。仍然存在相同的错误(无标准错误,ofc)

cmake指令文件

     cmake_minimum_required(VERSION 3.8)
     project(NA)

     set(CMAKE_C_STANDARD 11)



     find_package(GSL REQUIRED)
     find_package(CUDA REQUIRED)

     include_directories("${CUDA_INCLUDE_DIRS}")

     cuda_add_library(solvers STATIC
             cudaLS.cu
             cudaLS.h)

     target_link_libraries(solvers ${CUDA_LIBRARIES} ${CUDA_cusparse_LIBRARY} ${CUDA_cusolver_LIBRARY})
     target_compile_features(solvers PUBLIC cxx_std_11)
     set_target_properties( solvers
             PROPERTIES CUDA_SEPARABLE_COMPILATION ON)


     add_executable(NA main.c)
     set_target_properties(NA PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
     target_link_libraries(NA PRIVATE GSL::gsl m solvers)
朋友们,我做错了什么

UPD:

g++/gcc-7.3


Linux

好吧,我发现我用错误的方式做了什么

卡马克没问题。但是.h文件中的头必须修改为

    extern "C" void denseLS(int dim, cuComplex *A, cuComplex *b );
.c中的cuda函数必须在head(或单独的.h文件)中按如下方式清除


呃什么?NVCC默认使用C++编译。C与C++不是问题的根源。例如,我看不出您在哪里导入了什么是OS和gcc版本?为什么第二个定义与第一个不同?无论如何,您的一些错误消息似乎有不同的原因。我建议你考虑删除这个问题。
    extern "C" void denseLS(int dim, cuComplex *A, cuComplex *b );
    void denseLS(int dim, float complex *A, float complex *b);