简体   繁体   中英

LNK2001: unresolved external symbol threadIdx

I'm moving into C++/Cuda and ran into a compile error 'unresolved external symbol threadIdx' in 'MortalityTable.obj'.

I created a new C++ Cuda Runtime project, than compiles and runs fine. Then added a class MortalityTable.cu and .h , without any Cuda code, just regular C++. That compiles and runs fine.

The error starts when I try to add the Cuda kernel (If I comment it out all is well). I have these headers in MortalityTable.cu:

#include "cuda_runtime.h"
#include "device_launch_parameters.h"

And this is my kernel in that same file

__global__
void DevPLE(double* devple, double* devQxt, int maxAge, int years) {
    int i = threadIdx.x;
    double surv = 0, ple = 0;
    for (int age = 0; age < maxAge; age++) {
        surv = surv * (1.0f - devQxt[age * years + i]);
        ple += surv;
    }
    devple[i] = ple + 0.5;
}

Any ideas how I can get this to compile and run? I still have the example code in kernel.cu when you create a new Cuda Runtime Project, it has the same headers and does work. So it seems the project setup is ok, but for some reason does not work for MortalityTable.cu...

.cu file are compiled with nvcc, .c .cpp are compiled with cl.

When in a cuda project, you add a c++ file (cpp), but then you rename it with the .cu extension, VS won't also change the compiler.

If you edit you project file project.vcxproj you might want to check that your .cu file is included in a CudaCompile markup:

  <ItemGroup>
    <CudaCompile Include="cudacode.cu" />
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="code.cpp" />
  </ItemGroup>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM