cudaSetDevice not from library?

I can use cudaSetDevice from a program just fine. But I am developing a shared library and it doesn’t seem to work when I use it inside a lib. Is there a way to do that?