2

When the cuda_test.cu file is not included in the project, the code runs fine.

When such a file is included, I receive the following error message

mfcs100u.lib(dllmodul.obj) : error LNK2005: DllMain already defined in MSVCRT.lib(dllmain.obj)

cuda_test.cu has the following header files, a global function and a wrapper.

#include <cuda.h>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>

So I am not sure what causes this problem.

After some research, it seems this problem is fairly common and has fixes. But this starts giving trouble in a different part of the code. ("StdAfx.h" is included in all .cpp files, if this information is relevant).

It is a huge project written in C++ and I am trying to parallelize some parts of it.

Some help will be hugely appreciated. I can give extra details if needed.

Community
  • 1
  • 1
od08
  • 43
  • 4
  • Take a look at this post: [Compiling CUDA mex files with Visual Studio](http://www.orangeowlsolutions.com/archives/498). In particular, the post scriptum part. It describes the _error LNK2005: DllMain already defined in MSVCRT.lib_ and a way to solve it. – Vitality Dec 04 '13 at 08:25
  • Thanks. that helped. but ignoring `msvcrt.lib` completely was also giving error. what worked was ignoring both libraries `mfcs100u` and `msvcrt`, and adding them again as additional dependencies. ( change in order helps if I remember) – od08 Dec 04 '13 at 15:21

1 Answers1

1

You need to make sure that all parts of your app link against the same runtime.

In Solution Explorer, right click your .cu file and select Properties. Go to CUDA C/C++ > Host and make sure that Runtime Library is set to the same as for the rest of your project.

Roger Dahl
  • 15,132
  • 8
  • 62
  • 82