What is the proper way to avoid "duplicate symbols" when linking?

25 views
Skip to first unread message

Noon Chen

unread,
May 31, 2021, 4:41:16 PM5/31/21
to cython-users
Hi all,

Allow me to describe the code structure first:

1. C queue library & c_queue.pxd file.
2. put_stuff.pxd & put_stuff.pyx (import c_queue.pxd)
3. get_stuff_parse.pyx (import c_queue.pxd & put_stuff.pxd)

I created a setup file to compile get_stuff_parse.pyx, and I put "get_stuff_parse.pyx" and "put_stuff.pyx" in the sources since I only want to have a single .so file. 

Cython compiles sources into put_stuff.o & get_stuff_parse.o, and both contain symbols from the C queue library, leading to the "duplicate symbols" error.

I can think of two ways to make it work:
1. copy all the content from "put_stuff.pxd" & "put_stuff.pyx" into get_stuff_parse.pyx, but the code would be very messy.
2. compile put and get into two .so files, and import put_stuff.so at the runtime, but I have to manage two binary files, and it is not space-friendly.

I want to know how are you experts dealing with this situation? Is it possible to get only one binary file without the linking error? Any advice is appreciated!

Robert Bradshaw

unread,
Jun 6, 2021, 1:18:49 AM6/6/21
to cython...@googlegroups.com
You should compile c_queue as a separate shared object file, then link the two modules against it. This shouldn't be too space unfriendly. 

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/369168d7-9389-49e6-9fc6-4b21ac72291en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages