VS2008, link errors, already defined

Recently I changed to cuda toolkit 3.2.
After this change I can’t compile code which was able to compile on previous toolit.
I get link errors:

I have project which is defined as static libarry (*.lib).
I use /MD (Multithreaded DLL) option
I use Cuda Runtime APi build rule (v3.2) (previously I used cuda build rule v2.3.0)

In this project I have 3 .cu files:

c.cu <- this one is excluded from build, it contains device function

a and b have line: #include “c.cu”

when linking b.cu there is a warning that device function from c.cu is already defined in a.cu ; ignoring

then during library linking there is error that device function from c.cu is already defined in a.cu…

Well I think this error is kind of correct but before with previous toolkit I compiled it and it worked correctly - so what happened?
What I can do with it?
Please help i’ts my work on university and now i’ts broken because of new toolkit.

I seems that preaviously nvcc compiled all files from project in one time, and here it’s doing it separately

Are you sure you exclude c.cu from build? Rename it to cuh. Also check forward function declarations.

I checked it and I am sure…

Renaming to .cuh does nothing - if I rename to cuh and leave excluded from build.

If I rename to cuh and include them in build, it says “nvcc: Don’t know what to do with file_name.cuh”…

What do you mean forward declarations? Where I should pu them?

In last post I told u wrong - when I build library linker only says warnings “already exists; ignoring” and when the project which depends on this library tries to link then linker shows error “error: already defined”…

I created simple solution which contains this “situation” (a link to attached file below)

There are 2 projects:

testproj - static .lib with cuda functions

main - .exe app, depends on testproj

When I try to build this solution I got those errors I wrote about…

If u will try to build it I think the only thing u have to change is the custom build rules because my uses for default “NvCudaRuntimeApi.rules”

Thanks for ur reply
testproj.rar (60.6 KB)

Cause you use w1.cu you need to exclude a.cu b.cu c.cu and d.cu from build.
You have included a.cu in w1.cu already. I suggest not to include cu files cause cu is like cpp.

Yes I excluded them from build. Anyway the point is to keep device functions in separate files so I can reuse them.

The strange thing is that:

When I put device function into separate cu file, include it in build, and in another cu file put forward declaration of it, and try to use it, then compiler says that it found NOT_INLINED device function call and this is forbidden in cuda… true

But when I exclude cu file with device function from build and include it in two others cu files which use this function, then linker says it is already defined -> so wtf, it is inline function or not? if it is why linker see two of thi function if its just piece of code inside other function (inlined)…? How I can define device function in cu file to make it visible ONLY in this file not outside???

I found out something - if I exclude cu file with device function and make the device function as template or something like that, then I can include it as many times I want and linker wont say anything - but the stupid thing is that then I have to call function like device_function<0>(arg1,arg2) - > this is realy stupid - there must be some switch in vs not to link to inline functions…

So nobody knows how to store device function in separate files and then use them many times in multiple cu files?

I found the solution!!!
I was compiling against 1.3 and 2.0 -> on 1.3 device was inline, on 2.0 they are not!
So everything I had to do was to add inline keyword :D

so: device inline int function(args) -> in cu file excluded from build
and then you have to just include it in other cu files and there wont be link errors

thanks for help