TECHNOLOGY

NVCC separate compilation: device linking and host linking are different stages

In this article
THE QUICK TAKE

A host object file can contain unresolved device references; successful ordinary compilation does not prove that the device-call graph has been linked into the final executable.

Identify the cross-file dependency

The NVIDIA separate-compilation article explains how device functions can be organized across source files. Moving a helper out of a kernel’s translation unit changes a build dependency, even if the function declaration and mathematical behavior remain the same. A host linker finding ordinary C++ symbols is not sufficient evidence that the corresponding device-side call graph has been resolved.

Generate relocatable device code deliberately

The NVCC manual distinguishes executable device code from relocatable device code embedded in host objects. It documents --device-c as compilation with relocatable device code enabled, and --device-link as the stage producing executable device code from participating inputs. An object suffix alone does not identify which kind of embedded GPU code was produced. Inspect the actual compilation options rather than assuming every object can participate in the same device-link process.

The device-link output still participates in final host linking, and the manual explains why objects containing device code can also carry implicit host registration code. Omitting an apparently device-only object from the host link can therefore break the final artifact. Keep both link stages and their object sets visible when integrating a CUDA extension into a larger build system. Suppressing an unresolved-symbol error does not replace the missing stage or establish a working executable.

Use the build-system interface consistently

The CMake property enables separate compilation for CUDA files of a target. Consider a refactor that moves a helper into a static library: review which targets compile relocatable code and where device symbol resolution occurs, instead of adding unrelated linker flags until an error disappears. Build a small cross-file invocation as a fixture and verify that the final application actually calls the intended device helper under the selected target architecture.

Record the complete artifact path

Keep source ownership, compiler options, embedded device-code mode, device-link inputs, host-link inputs, and target architectures. Guides to CUDA version scopes and GPU acceptance evidence provide context. Check the final executable after build changes. A meaningful fix reproduces the intended two-stage linking contract rather than depending on one development machine’s accidental object visibility or confusing host-side library loading with resolution of device-side function references.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles