Discussion:
[Bf-python] Including 3rd party modules in a Blender addon
Jose Juan Tapia
2014-04-10 15:48:59 UTC
Permalink
Hello everyone,

I wish to include the libsbml library in one of my blender addons. Although
i was able to succesfully do this in Linux, I'm having problems getting it
to load in blender's python in my Windows box. After writing to the libsbml
library developers, they came back with the following response
all the third party dependencies are statically linked into the libSBML
python bindings. So from our side all that is needed is the> >>_libsbml.pyd
as well as the __init__.py script. The _libsbml.pyd that we build depends
however on the specific python version. That is why we need to distribute
so many different versions of it.
When I looked at Blender it seemed to be using Python 3.3.0. (Which is
unfortunately the only python binaries we do not currently >>distribute).
So i went ahead and created a set of binaries for the 'official' python
3.3. Looking at the dependencies, it depends on >>python33.dll and
python3.dll. However, Blender only comes along with the python33.dll.
the best thing to do would be to be able to link directly against the
library that blender uses, unfortunately there are no lib files
distributed with blender. So i'm afraid I cannot help there. It would
help to know how precisely they built the numpy module they >>distribute
and then use the same build procedure for libSBML.


My specific questions would then be

1. whether it's possible to either get python3.dll from the official python
distribution and use it with blender, or
2. if there is a set of lib's that blender uses that I could compile my own
version of libsbml against so that I can include it in my addon. 3.
Alternatively, what are the set of steps that one needs to follow to
compile a library against Blender python's libs and dlls (for example, like
the cited mail states, how was Blender's numpy compiled).

Thanks for the help. Yours,
--
Jos? Juan Tapia Valenzuela
Research Associate
University of Pittsburgh
3076.1 Biological Sciences Tower 3
Pittsburgh, PA 15260
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/bf-python/attachments/20140410/79808fa2/attachment.htm
Michel Anders
2014-04-12 18:27:34 UTC
Permalink
Hi,



Did anyone have any luck in compiling the example_nt extension from the python source distribution w. msvc 2013?



I copied it into lib\win64_vc12\python, opened the solution in msvc 2013 and after pointing the include directories and library directories o the ones in the same python lib it compiles ok but complains about not being able to find initexample although there is an /export:initexample defined in the properties. Anyone have a clue?



Cheers,



-- Michel.



1>------ Build started: Project: example, Configuration: Debug Win32 ------

1> example.c

1>e:\blender source environment\lib\win64_vc12\python\include\python3.3\pymath.h(22): warning C4273: 'round' : inconsistent dll linkage

1> e:\visual studio 2013\vc\include\math.h(516) : see previous definition of 'round'

1>example.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:LBR' specification

1>LINK : error LNK2001: unresolved external symbol initexample

1>.\Debug/example_d.lib : fatal error LNK1120: 1 unresolved externals

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/bf-python/attachments/20140412/3a4360f0/attachment.htm
Michel Anders
2014-04-13 09:54:26 UTC
Permalink
Solved: it helps if you compile for the x64 platform (the example solution only contains win32 configurations and I think this choice not only affects the generated code but also the name mangling used to generate decorated names in the .dll, hence the linker errors)



I should?ve looked better :-/



BTW: the /export:initexample switch is wrong: there is no need to explicitly export anything (the PyMODINIT_FUNC macro takes care of that) and although the python docs state otherwise, the module initialization function should be called PyInit_xxxxxx (as it is in the ectuall example code) and NOT initxxxxxxx (as stated in the accompanying text).



Cheers,



-- Michel.



From: bf-python-bounces at blender.org [mailto:bf-python-bounces at blender.org] On Behalf Of Michel Anders
Sent: zaterdag 12 april 2014 20:28
To: 'Blender Foundation Python list'
Subject: [Bf-python] compile a native c extension for python with msvc 2013



Hi,



Did anyone have any luck in compiling the example_nt extension from the python source distribution w. msvc 2013?



I copied it into lib\win64_vc12\python, opened the solution in msvc 2013 and after pointing the include directories and library directories o the ones in the same python lib it compiles ok but complains about not being able to find initexample although there is an /export:initexample defined in the properties. Anyone have a clue?



Cheers,



-- Michel.



1>------ Build started: Project: example, Configuration: Debug Win32 ------

1> example.c

1>e:\blender source environment\lib\win64_vc12\python\include\python3.3\pymath.h(22): warning C4273: 'round' : inconsistent dll linkage

1> e:\visual studio 2013\vc\include\math.h(516) : see previous definition of 'round'

1>example.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:LBR' specification

1>LINK : error LNK2001: unresolved external symbol initexample

1>.\Debug/example_d.lib : fatal error LNK1120: 1 unresolved externals

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/bf-python/attachments/20140413/0146ff1a/attachment.htm
Loading...