nvcc error (fatal error LNK1120) Trouble compiling

Hello, I want to compile the following kernel (file invertVectorElements.cu) for use it later in a jcuda program.

extern "C"

__global__ void invertVectorElements(float* vector, int n)


    int i = threadIdx.x;

    if (i < n)


       vector[i] = 1.0f / vector[i];



The result of compilation is

>nvcc invertVectorElements.cu







LIBCMT.lib(crt0.obj) : error LNK2019: símbolo externo _main sin resolver al que hace refrencia en la función ___tmainCRTStartup

a.exe : fatal error LNK1120: 1 externos sin resolver

What’s the problem? How can I solve this?


The default compilation tries to build an executable. Thus it needs function main() defined in one of the input files. Here you have just a single file, and it doesn’t define main(). Try something along these lines:

nvcc -c -o invertVectorElements.obj invertVectorElements.cu

The flag -c instructs the compiler to compile but not link. The flag -o and its argument specify the name of the objectfile produced. You can then link the generated object file with other object files, exactly one of which should contain a function main().

These mechanisms (compile & link vs compile-only, specifying object files) are commonly found in compilers, just the names of the flags tend to differ a bit between various the compilers.