Makefile for creating shared object using 'wrong architecture' errors when loading


I’m trying to compile my CUDA project on OSX but encountering some errors which I don’t know how to solve. I compile my project on Linux with just a few extra arguments to nvcc:

nvcc -shared -Xcompiler "-fPIC" -c -o out.o -I<includes..>

The final linking, on Linux, is done with gcc as following:

gcc -std=gnu99 -shared -o in.o -lcuda -lcudart -lcublas

So I’m trying to create a Makefile for my project on OSX, preferably using the file (I don’t have experience making Makefiles using these rules btw).

So I added the following line to my Makefile:

COMMONFLAGS += -shared -Xcompiler "-fPIC"

but I’m unsure how I tell to create a shared object for the linking phase, any ideas?

Currently, if I manually link the objects files into a shared object, I get the following error when loading the file:

unable to load shared library '':

  dlopen(, 6): no suitable image found.  Did find: mach-o, but wrong architecture

If someone can advice what to do, or what other information is needed, I would be very grateful!

System: Apple MacBook Pro 13 inch, Nvidia 320M

CUDA version: 3.0, examples are all working fine.