Build issue with Python 3.4.2 Fedora 22

108 views
Skip to first unread message

Greg N

unread,
Jul 24, 2015, 11:09:06 PM7/24/15
to py-leveldb
I ran into an issue with an updated version of Fedora 22 with Python 3.4 (python3-3.4.2-6.fc22.x86_64) getting a "template with C linkage" error during virtualenv python 3 pip/easy_install of py-leveldb. Similar issues when attempting to build from source https://pypi.python.org/packages/source/l/leveldb/leveldb-0.193.tar.gz using `python3 setup.py build`.

Details
Distro: Fedora release 22
Python version: python3-3.4.2-6.fc22.x86_64
PIP version: python3-pip-6.0.8-1.fc22.noarch

Example Errors
(py3env)[root@fedora22 ~]# pip install leveldb
[...]
    In file included from /usr/include/python3.4m/pyatomic.h:8:0,
                     from /usr/include/python3.4m/Python.h:53,
                     from leveldb_ext.h:8,
                     from leveldb_ext.cc:6:
    /usr/include/python3.4m/dynamic_annotations.h:472:3: error: template with C linkage
       template <class T>
       ^
    error: command 'gcc' failed with exit status 1
-------------------------------------------------------------------------------------------------
(py3env)[root@fedora22 ~]# easy_install leveldb
[...]
In file included from /usr/include/python3.4m/pyatomic.h:8:0,
                 from /usr/include/python3.4m/Python.h:53,
                 from leveldb_ext.h:8,
                 from leveldb_ext.cc:6:
/usr/include/python3.4m/dynamic_annotations.h:472:3: error: template with C linkage
   template <class T>
   ^
error: Setup script exited with error: command 'gcc' failed with exit status 1
-------------------------------------------------------------------------------------------------
[root@fedora22 leveldb-0.193]# python3 setup.py build
running build
running build_ext
building 'leveldb' extension
[...]
In file included from /usr/include/python3.4m/pyatomic.h:8:0,
                 from /usr/include/python3.4m/Python.h:53,
                 from leveldb_ext.h:8,
                 from leveldb_ext.cc:6:
/usr/include/python3.4m/dynamic_annotations.h:472:3: error: template with C linkage
   template <class T>
   ^
error: command 'gcc' failed with exit status 1
-------------------------------------------------------------------------------------------------

I was able to work past this by adjusting the leveldb_ext.h header to look like:

// Copyright (c) Arni Mar Jonsson.
// See LICENSE for details.


#ifndef __LEVELDB__MODULE__H__
#define __LEVELDB__MODULE__H__


extern "C++" {
#include <Python.h>
}

extern "C" {
#include "structmember.h"

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
}

#include <leveldb/db.h>
#include <leveldb/write_batch.h>
#include <leveldb/comparator.h>
#include <leveldb/cache.h>


#include <vector>

I am now able to successfully build using `python3 setup.py build` and install with `python3 setup.py install`.

I test py-leveldb while in python3:
$ python3
Python 3.4.2 (default, Jul  9 2015, 17:24:30) 
[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import leveldb
>>> db = leveldb.LevelDB('./db')
>>> db.Put(b'hello', b'world')
>>> print(db.Get(b'hello'))
bytearray(b'world')
>>>

At this point it only looks like an issue related to Python 3.4+ as there appears to be a Python header which uses C++ leading to error extern "C" if <Python.h> is included. I can work around it by either moving the "#include <Python.h>" out of the extern "C" to just above it or declaring it in extern "C++" like I did in my example above.

Has anyone else run into this?
Reply all
Reply to author
Forward
0 new messages