# making shared object file

**URL:** <https://forums.developer.nvidia.com/t/making-shared-object-file/10553>\
**Category:** CUDA Programming and Performance\
**Created:** [July 1, 2009, 8:16pm UTC](https://forums.developer.nvidia.com/t/making-shared-object-file/10553 "2009-07-01T20:16:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BROSE](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@BROSE](https://forums.developer.nvidia.com/u/BROSE)\
**Post date:** [July 1, 2009, 8:16pm UTC](https://forums.developer.nvidia.com/t/making-shared-object-file/10553/1 "2009-07-01T20:16:05Z")

</div>

Hello,

I am trying to make a .so file with the nvcc compiler. I basically took a code that was previously written for a linear CPU and re-wrote it for a GPU.

The compiler options I used to make this file with gcc were

[codebox]

gcc -fPIC -c filename.c -std=c99

gcc -shared -o filename.so filename.o

[/codebox]

Now I am trying to do the same thing but with the new code for the gpu. I see that nvcc has a -shared option and I have tried many combinations of commands.

if my file is filename.cu what should I type in the command line to compile and link it to make filename.so ???

---

<div class="post-metadata">

**Author:** ![seibert](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/seibert/32/520688_2.png) [@seibert](https://forums.developer.nvidia.com/u/seibert)\
**Post date:** [July 1, 2009, 11:45pm UTC](https://forums.developer.nvidia.com/t/making-shared-object-file/10553/2 "2009-07-01T23:45:38Z")

</div>

nvcc -o mygpulib.so -shared mykernel.cu

If you are on a 64-bit Linux distribution, you need to run instead:

nvcc -o mygpulib.so --compiler-options ‘-fPIC’ -shared mykernel.cu

---

<div class="post-metadata">

**Author:** ![BROSE](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@BROSE](https://forums.developer.nvidia.com/u/BROSE)\
**Post date:** [July 6, 2009, 5:45pm UTC](https://forums.developer.nvidia.com/t/making-shared-object-file/10553/3 "2009-07-06T17:45:50Z")

</div>

Ok thanks, doing what you posted for the 64 bit linux system successfully creates a shared object file, but when I run my script that uses this file I get an error loading the file. To try and see if it was the compiler options that were wrong, I took the non-cuda version of my file that successfully works with my program when compiled with the gcc options above and I compiled it with nvcc with the options you provided. I get a successful compile, but when I run my script that uses the shared object file I get a bus error? can anyone explain this to me?
