python - Cython producing duplicate symbols _PyInit_ and ___pyx_module_is_main_ -


when trying port python code cython, following linker error message:

cls ~/workspace/prototypes/plpcython $ python3 setup.py build_ext --inplace running build_ext cythoning src/graph.pyx src/graph.c cythoning src/community.pyx src/community.c building 'plpcython' extension creating build creating build/temp.macosx-10.8-x86_64-3.3 creating build/temp.macosx-10.8-x86_64-3.3/src cc -wno-unused-result -fno-common -dynamic -dndebug -g -o3 -wall -wstrict-prototypes -i/usr/local/include -i/usr/local/opt/sqlite/include -i/usr/local/cellar/python3/3.3.0/frameworks/python.framework/versions/3.3/include/python3.3m -c src/graph.c -o build/temp.macosx-10.8-x86_64-3.3/src/graph.o cc -wno-unused-result -fno-common -dynamic -dndebug -g -o3 -wall -wstrict-prototypes -i/usr/local/include -i/usr/local/opt/sqlite/include -i/usr/local/cellar/python3/3.3.0/frameworks/python.framework/versions/3.3/include/python3.3m -c src/community.c -o build/temp.macosx-10.8-x86_64-3.3/src/community.o src/community.c:1414:19: warning: expression result unused [-wunused-value]     pyobject_init(o, t);     ~~~~~~~~~~~~~~^~~~~ /usr/local/cellar/python3/3.3.0/frameworks/python.framework/versions/3.3/include/python3.3m/objimpl.h:163:69: note: expanded macro 'pyobject_init'     ( py_type(op) = (typeobj), _py_newreference((pyobject *)(op)), (op) )                                                                     ^ 1 warning generated. cc -bundle -undefined dynamic_lookup -l/usr/local/lib -l/usr/local/opt/sqlite/lib build/temp.macosx-10.8-x86_64-3.3/src/graph.o build/temp.macosx-10.8-x86_64-3.3/src/community.o -o /users/cls/workspace/prototypes/plpcython/plpcython.so duplicate symbol _pyinit_plpcython in:     build/temp.macosx-10.8-x86_64-3.3/src/graph.o     build/temp.macosx-10.8-x86_64-3.3/src/community.o duplicate symbol ___pyx_module_is_main_plpcython in:     build/temp.macosx-10.8-x86_64-3.3/src/graph.o     build/temp.macosx-10.8-x86_64-3.3/src/community.o ld: 2 duplicate symbols architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation) error: command 'cc' failed exit status 1 

apparently duplicate symbols produced. _pyinit_* , ___pyx_module_is_main_?

these 2 source files try cythonize: graph.pyx

class graph:      def __init__(self, n=0):         self.n = n         self.m = 0           self.z = n  # max node id         self.adja = [[] in range(self.z)]         self.deg = [0 in range(self.z)]      def maxnodeid(self):         return self.z      def numberofnodes(self):         return self.n      def numberofedges(self):         return self.m      def addedge(self, u, v):         if (u == v):             self.adja[u].append(v)             self.deg[u] += 1         else:             self.adja[u].append(v)             self.adja[v].append(u)             self.deg[u] += 1             self.deg[v] += 1         self.m += 1      def hasedge(self, u, v):         w in self.adja[u]:             if w == v:                 return true         return false       def degree(self, u):         return self.deg[u]      def fornodes(self, handle):         # assumtion: nodes exist         u in range(self.z):             handle(u)      def foredges(self, handle):         u in range(self.z):             v in self.adja[u]:                 if v <= u:                     handle(u, v)      def forneighborsof(self, u, handle):         v in self.adja[u]:             handle(v) 

and community.pyx

def numberofcommunities(zeta, g):     labels = set()     label in zeta:         if label not none:             labels.add(label)     return len(labels)   def coverage(zeta, g):     intra = 0     inter = 0     m = g.numberofedges()      def scan(u, v):         nonlocal intra         nonlocal inter         if zeta[u] == zeta[v]:             intra += 1         else:             inter += 1      g.foredges(scan)      print("intra-community edges: ", intra)     print("inter-community edges: ",inter)      assert (inter + intra == m)     coverage = intra / m     return coverage 

i believe cython supports compilation of single source file single module. either compile 2 files 2 separate modules or use include statement (http://docs.cython.org/src/userguide/language_basics.html#the-include-statement) combine them in single source file.


Comments