Included file with reusable device *functions* creating link errors in debug for two odd cases

I have a file with a common set of CUDA device functions (not even one global function kernel). No host functions are in this file.

I include the file in two independent kernels and they compile fine.

The entire application successfully compiles and links in non-Debug mode.

Compiling and linking in Debug mode results in a “multiply defined symbols” linker error (LNK2005) for only those kernel functions that are not directly called by the including kernels or not called at all.

There are two cases and workarounds:

  1. Functions that are only called by other functions in this included file produce “multiply defined symbols” link errors. Marking them as forceinline fixed those errors.

  2. A function that is not used anywhere produces a multiply defined link error. Commenting it out entirely solved that problem (ugh).

I’m on VS2010 + CUDA 5.0.

Again, this is only an issue when compiling a Debug target and the kernels are independent.

Thoughts?

Derp!

Explicitly decorating the device function with a ‘static’ specifier solves my problem:

#define DEVICE_STATIC_FUNCTION_QUALIFIERS   static DEVICE_FUNCTION_QUALIFIERS
#define DEVICE_STATIC_INTRINSIC_QUALIFIERS  static DEVICE_INTRINSIC_QUALIFIERS

It’s probably a good habit to think about static and extern specifiers with the new separate compilation feature in CUDA 5.0.

Thanks to @SPWorley for the hint!