[Biopython-dev] Work towards getting KDTree compiling

Brad Chapman chapmanb at uga.edu
Mon Apr 19 07:56:16 EDT 2004


Hello Thomas and all;
Since Michiel wrote about the problems that were causing the KDTree
C++ extension to fail, I've been taking a look into seeing how we
might fix that problem and get KDTree compiled by default in
Biopython. To quote from Michiel's mail:

> I tried compiling KDTree on a Unix machine running SunOS 5.8. It has two 
> Python versions, one compiled with gcc and the other one with the native cc 
> compiler. Distutils uses the same compiler as the one used to compile 
> Python itself. The gcc-Python compiled KDTree without problems, but the 
> cc-Python did not, as cc doesn't handle C++. The same problem may occur on 
> other Unix platforms if the native compiler rather than gcc was used to 
> compile Python.

I was a bit surprised that distutils didn't recognize the C++ code
as such and use a C++ compiler, so I dug around a bit in the
distutils code and looked at how it figured out what is C++ and what
is C. Turns out, it uses the filename extensions to do this via the
following dictionary:

    language_map = {".c"   : "c",
                    ".cc"  : "c++",
                    ".cpp" : "c++",
                    ".cxx" : "c++",
                    ".m"   : "objc",
                   }

I guess if it doesn't find it here, it defaults to using the C
compiler, which is what it seemed like it was doing.

As I dug further, I discovered you can set the language when
specifying the extension, and then this'll be used instead of the
filename extension detection.

So, I checked in a modified setup.py that compiles KDTree by default
and sets the language to c++:
    
Extension('Bio.KDTree._CKDTree',
              ["Bio/KDTree/KDTree.C",
               "Bio/KDTree/KDTree.swig.C"],
              libraries=["stdc++"],
              language="c++"
              ),

I hope maybe this will fix the problem on non-gcc systems and get
KDTree compiled by default.

I was wondering if people on potential problem systems (Solaris,
Windows, Mac OSX) would mind testing this out to see if it compiles
happily. If so, I'll leave it in for the next release -- otherwise,
we'll have to keep working.

Thanks much for any reports (hopefully of success :-).
Brad



More information about the Biopython-dev mailing list