PyCuda C++ kernel "error: this declaration may not have extern "C" linkage"

I tried using std::tuple in my kernel code, but received many error: this declaration may not have extern "C" linkage errors that pointed to utility and tuple

It complains on the include. The following repros for me.

from pycuda.compiler import SourceModule
mod = SourceModule("""#include <tuple>""")

Do I need to do something special in my kernel code or in my Python code to specify I want to use the C++ compiler?

Cuda version: 11.8

PyCuda version: 2022.2.1

Hi john.novak1024,

We may need to move your post to another forum since I’m not familiar with Python or pyCUDA. However, I just looked at pyCUDA’s Documentation for SourceModule:

Where it says:

Unless no_extern_c is True , the given source code is wrapped in extern “C” { … } to prevent C++ name mangling.

Given “tuple” uses templating, it can be wrapped in an extern “C” block.

Can you try adding “no_extern_c=True” to see if it works around this issue?


That worked! Thanks! Of course, now there are issues with name mangling, but it looks like my issues can be fixed by following the answers found at

cuda - PyCUDA either fails to find function in NVIDIA source code or throws ‘may not have extern “C” Linkage’ error - Stack Overflow


cuda - How to invoke a constexpr function on both device and host? - Stack Overflow