Hi, I wrote an extension for sfepy, that requires compiling and linking additional fortran sources (invoked by cython). I found out, that these libraries can be easily added using distutils config.add_library() function, but there is the problem. The --fcompiler command doesn't propagate to the stage where the libraries are compiled, so the default (and in my case wrong) compiler is used. (If I try compile the files using add_extension method, they are compiled by desired compiler, but I need combine more sources in one extension so I think that I can't use add_extension).
Is there any way how to force python to use the right compiler, or at least hardcode the compiler in the setup.py?
Thanks a lot for suggestions, Matyas My setup.py: def configuration(parent_package='', top_path=None): import os.path as op from numpy.distutils.misc_util import Configuration from sfepy import Config
site_config = Config()
auto_dir = op.dirname(__file__) auto_name = op.split(auto_dir)[-1] config = Configuration(auto_name, parent_package, top_path)
flags= site_config.compile_flags() flags.append('-I'+os.path.dirname(__file__))
config.add_library('xc_default', ['default/dft.c'], extra_compile_args=flags, f2py_options = '--fcompiler=gnu95', extra_link_args=site_config.link_flags() )
config.add_library('xc_vackar', ['vackar/vscxc.f90'], extra_compile_args=flags, f2py_options = {'fcompiler' : 'gnu95'}, extra_link_args=site_config.link_flags()
Hi Matyas,
for me, the add_extension works also for extensions with several source files - just list them in the sources argument, e.g.: sources=['src1.c', 'src2.c'] - check the setup.py files in sfepy/fem/extmods or sfepy/terms/extmods. But it's true I do not compile fortran... You mean f2py_options do not work, right?
I think you know about [1], where supported arguments of each command are shown. So it what you are trying to do should work, try asking the numpy guys?
r.
[1] http://docs.scipy.org/doc/numpy/reference/distutils.html
On 08/29/2012 02:38 PM, Matyáš Novák wrote:
Hi, I wrote an extension for sfepy, that requires compiling and linking additional fortran sources (invoked by cython). I found out, that these libraries can be easily added using distutils config.add_library() function, but there is the problem. The --fcompiler command doesn't propagate to the stage where the libraries are compiled, so the default (and in my case wrong) compiler is used. (If I try compile the files using add_extension method, they are compiled by desired compiler, but I need combine more sources in one extension so I think that I can't use add_extension).
Is there any way how to force python to use the right compiler, or at least hardcode the compiler in the setup.py?
Thanks a lot for suggestions, Matyas
My setup.py: def configuration(parent_package='', top_path=None): import os.path as op from numpy.distutils.misc_util import Configuration from sfepy import Config
site_config = Config() auto_dir = op.dirname(__file__) auto_name = op.split(auto_dir)[-1] config = Configuration(auto_name, parent_package, top_path) flags= site_config.compile_flags() flags.append('-I'+os.path.dirname(__file__)) config.add_library('xc_default', ['default/dft.c'], extra_compile_args=flags, f2py_options = '--fcompiler=gnu95', extra_link_args=site_config.link_flags() ) config.add_library('xc_vackar', ['vackar/vscxc.f90'], extra_compile_args=flags, f2py_options = {'fcompiler' : 'gnu95'}, extra_link_args=site_config.link_flags()
Hi, when I add fortran sources to add_extension, the resulting module has only methods from one of the sources, nothing else. (And I only need these methods for Cython so I don't need python wrapers and f2py for them at all). Yes, it seems that f2py options don't work, I think the root is in the fact, that libraries added by add_library are not compiled by f2py, but only by fortran compiler, so there is no "space" to apply these options. I had read the distutils documentation and find nothing relevant (but I could miss something, obviously). Contacting numpy-guys is already in progress :-) But I realize that there is maybe one ugly hack: compile them as standalone extension and then pass the .so files to the linker of the "main" extension. It should work, but it's platform dependent (name of extension files can differ). Thank for reply Matyas PS: Sorry for missing subjec, i missed it when I changed sender adress to have the message accepted.
On 08/29/2012 03:37 PM, Matyáš Novák wrote:
Hi, when I add fortran sources to add_extension, the resulting module has only methods from one of the sources, nothing else. (And I only need these methods for Cython so I don't need python wrapers and f2py for them at all).
I am just wildly guessing, but adding those sources to "depends" would not help?
Yes, it seems that f2py options don't work, I think the root is in the fact, that libraries added by add_library are not compiled by f2py, but only by fortran compiler, so there is no "space" to apply these options. I had read the distutils documentation and find nothing relevant (but I could miss something, obviously). Contacting numpy-guys is already in progress :-)
Good :) Because this is not something I feel like being able to be of much help...
But I realize that there is maybe one ugly hack: compile them as standalone extension and then pass the .so files to the linker of the "main" extension. It should work, but it's platform dependent (name of extension files can differ).
I would be pragmatic in this case for the moment :)
Thank for reply Matyas
PS: Sorry for missing subjec, i missed it when I changed sender adress to have the message accepted.
No problem!
r.
participants (2)
-
Matyáš Novák
-
Robert Cimrman