3

Perhaps I should split this into separate questions, but having tried all of this, I wonder if they're not all interrelated.

Here's the backstory: There are some C libraries in both Linux and Windows. Someone used swig in Linux to expose the C libraries' API to Python. He more or less wrote a build script (.i file) for swig, and swig created a wrapper C file, and he used gcc to compile that C file, linking to the original libraries to get a Python module.

Now I've been handed his work and asked to do it for the Windows libraries. The hope was that I could find a quick way of using his .i files to create one for Windows. We use Visual Studio 2010.

I don't know swig much, and am not that knowledgeable in C or the Visual Studio environment, so I finally gave up experimenting and decided to ask here.

The questions:

  1. The C libraries I have are static. Is that OK? Can I just use the wrapper file swig produces and link it to the static libraries to create a dynamic library (for use in Python)? If the answer is no, this actually could get complicated. Basically, I want to expose the API of one particular library (call it "A"). That library, in turn, relies on "L", "C" and "D". I have access to the source code for "A" and "L", so I can compile them any way I please, but "C" and "D" is out of my control - they are static libraries.

  2. In Windows, for use with Python, what exactly is the output file I want? A DLL? Should it have a .pyd extension? I'm familiar with all this in Linux (used Cython in the past), but not in Windows.

  3. I'd really like help on handling this in Visual Studio 2010. The docs cover Visual Studio 6 and a few versions above, but are relatively sparse in details. Instead they suggest I just use the .dsp/.dsw files that come with SWIG. I did try that using a simple example that comes with it. VS2010 converted the dsp/dsw file to VS2010 format, and it kind of all works - creating a .pyd file. However, when I go into the project/solution's properties, I see no settings for swig, or for creating something with a .pyd extension! The custom/post-build settings are empty! I suspect when VS2010 converted the project files to its format, it took care of all the post-build settings, but doesn't display them.

Many thanks!

user1462309
  • 480
  • 2
  • 10
  • Can't comment on the windows specifics much, but I think the .pyd files are just .dlls with another name. ([refrerence](http://docs.python.org/faq/windows.html#is-a-pyd-file-the-same-as-a-dll)) – Flexo Jul 22 '12 at 16:43

1 Answers1

1
  1. There shouldn't be any problems with that. Just add "L", "C" and "D" libraries in VS as you usually add external libraries.

  2. Yes. Target should be Dynamic Library (.dll) but output file should be renamed as _something.pyd (See link below how to configure the project)

  3. SWIG could be integrated in VS solution build toolchain. I wrote a manual of how to use SWIG and Visual studio some time ago and now updated it for you:

How to use SWIG with Visual Studio 2010

Community
  • 1
  • 1
MajesticRa
  • 13,770
  • 12
  • 63
  • 77
  • Many thanks. Apparently I had done it more or less correctly, but just didn't rename it to a pyd. The thought had crossed my mind, but so did 10 or so other possibilities as to why it wasn't working, and your answer really helped in my not wasting time trying every conjecture I came up with. And thanks for the link on how to do it in VS2010 - that was even more useful than solving my original problem. – user1462309 Jul 24 '12 at 06:18