Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

CUDA: LNK2005 Linker Errors

📅 2011-Jan-31 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ cuda, errors, linker, visual c++ ⬩ 📚 Archive

The Problem

When building a Visual Studio solution which has CUDA source files (*.cu), LNK2005 linker errors of the following kind might be seen:

LIBCMT.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRT.lib(MSVCR90.dll)

What does it mean?

This indicates a mismatch between the kind of C runtime library used by the CUDA Build Rule and that used for the rest of the Visual C++ project.

How to fix it?

This problem can be fixed by making both of these use the same kind of C runtime library. For example, if the Visual C++ project is compiled using Multi Threaded DLL (/MD) and the CUDA build rule has Multi Threaded (/MT), then change the CUDA build rule to use /MD too.

Tried with: CUDA 3.2 and Visual Studio 2008