How do you make python recognize read a precompiled shared file?
I have a package I've created in C++ and, have already compiled it into a shared library.
When I link against it with my own main function, I can initialize the package by calling the initialization function directly, initfoo, and everything works fine.
How do I get python to recognize my shared library as a package, so I can just type:
import foo
running from the regular python interpreter?
I'm not interested in using distutils to compile the file, since the compilation has to be part of the regular cmake build system. I just need to create whatever package files necessary to load my开发者_运维百科 shared library.
Update: I now have it working. The issue was with cmake defaulting to a lib prefix for shared library names. To fix this requires
SET_TARGET_PROPERTIES(foo PROPERTIES PREFIX "")
and for Mac OS X
SET_TARGET_PROPERTIES(foo PROPERTIES SUFFIX ".so")
If you have a shared library with initfoo
symbol exported (note: since you've tagged the question c++ — make sure it's an extern "C"
symbol, otherwise name mangling will prevent the interpreter from finding it), then it's already a Python module, and can be loaded directly, with no further work. You only need to make sure it's on search path, just like any other module.
精彩评论