kernel wrapper linking problem

say I want to do a kernel wrapper for cuda kernel

in project.cu file:

#include "project.h"

__global__ void kernel(

    ... ...

){

    ... ...

}

extern "C" void kernel_wrapper(

    ... ...

){

    ... ...

    kernel<<<...,...>>>(... ...);

}

in project.h file:

extern "C" void kernel_wrapper(... ...);

in main.cpp file:

#include "project.h"

int main(void)

{

    ... ...    

    kernel_wrapper(... ...);

    ... ...

}

Visual studio 2008 gives following error in release mode.

1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)

    1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: ___iob_func already defined in LIBCMT.lib(_file.obj)

    1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _printf already defined in LIBCMT.lib(printf.obj)

    1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _fprintf already defined in LIBCMT.lib(fprintf.obj)

    1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _exit already defined in LIBCMT.lib(crt0dat.obj

)

and some of the errors in debug mode:

1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _printf already defined in LIBCMT.lib(printf.obj)

1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)

1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _exit already defined in LIBCMT.lib(crt0dat.obj)

1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: ___iob_func already defined in LIBCMT.lib(_file.obj)

1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _fprintf already defined in LIBCMT.lib(fprintf.obj)

1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _free already defined in LIBCMT.lib(free.obj)

1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library

1>updateHost.cu.obj : error LNK2001: unresolved external symbol _cudaGetErrorString@4

1>initGPU.cu.obj : error LNK2019: unresolved external symbol _cudaGetErrorString@4 referenced in function "int __cdecl cutGetMaxGflopsDeviceId(void)" (?cutGetMaxGflopsDeviceId@@YAHXZ)

1>shutDownGPU.cu.obj : error LNK2001: unresolved external symbol _cudaGetErrorString@4

... ...

It seems I have some runtime library linking problems, anyone knows how to resolve this. Thanks.

say I want to do a kernel wrapper for cuda kernel

in project.cu file:

#include "project.h"

__global__ void kernel(

    ... ...

){

    ... ...

}

extern "C" void kernel_wrapper(

    ... ...

){

    ... ...

    kernel<<<...,...>>>(... ...);

}

in project.h file:

extern "C" void kernel_wrapper(... ...);

in main.cpp file:

#include "project.h"

int main(void)

{

    ... ...    

    kernel_wrapper(... ...);

    ... ...

}

Visual studio 2008 gives following error in release mode.

1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)

    1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: ___iob_func already defined in LIBCMT.lib(_file.obj)

    1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _printf already defined in LIBCMT.lib(printf.obj)

    1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _fprintf already defined in LIBCMT.lib(fprintf.obj)

    1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _exit already defined in LIBCMT.lib(crt0dat.obj

)

and some of the errors in debug mode:

1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _printf already defined in LIBCMT.lib(printf.obj)

1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)

1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _exit already defined in LIBCMT.lib(crt0dat.obj)

1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: ___iob_func already defined in LIBCMT.lib(_file.obj)

1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _fprintf already defined in LIBCMT.lib(fprintf.obj)

1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _free already defined in LIBCMT.lib(free.obj)

1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library

1>updateHost.cu.obj : error LNK2001: unresolved external symbol _cudaGetErrorString@4

1>initGPU.cu.obj : error LNK2019: unresolved external symbol _cudaGetErrorString@4 referenced in function "int __cdecl cutGetMaxGflopsDeviceId(void)" (?cutGetMaxGflopsDeviceId@@YAHXZ)

1>shutDownGPU.cu.obj : error LNK2001: unresolved external symbol _cudaGetErrorString@4

... ...

It seems I have some runtime library linking problems, anyone knows how to resolve this. Thanks.

Hi, It looks like you are trying to mix MS runtime libraries for the two source files (main.cpp, project.cu). Check how you compile all your source. Choose /MT or /MD, but not both, for all compilations. An alternative–not as nice–is to merge project.cu and main.cpp into one file. --Ken

Hi, It looks like you are trying to mix MS runtime libraries for the two source files (main.cpp, project.cu). Check how you compile all your source. Choose /MT or /MD, but not both, for all compilations. An alternative–not as nice–is to merge project.cu and main.cpp into one file. --Ken