Using a C library in Cython

45 views
Skip to first unread message

Christoph Baumgarten

unread,
Dec 29, 2020, 12:44:15 AM12/29/20
to cython-users

Hi,

I am trying to use functionality from the C library UNU.RAN (UNU.RAN - Universal Non-Uniform RANdom number generators (wu.ac.at)) from Python / Cython. Example of the functionality I am trying to use: http://statmath.wu.ac.at/software/unuran/doc/unuran.html#Example_005f0 

After installing the library following the UNU.RAN documentation, I tried to follow the tutorial Using C libraries — Cython 3.0a6 documentation. I run into an error '... can not be used when making a shared object; recompile with -fPIC '

Before I investigate how to compile the library with that option (not my area of expertise at all, using the --with-pic in the installation options did not help), I wanted to ask if there is another (potentially easier) way to access a function from the library. I had a look at Interfacing with External C Code — Cython 3.0a6 documentation : 'When you want to call C code from a Cython module, usually that code will be in some external library that you link your extension against. However, you can also directly compile C (or C++) code as part of your Cython module. ' I was wondering if the latter approach could make sense in my case. Is there an example of how that works in detail?

Thanks a lot for your help (and apologies in case my problem description is not very clear)

Christoph




Robert Bradshaw

unread,
Dec 30, 2020, 2:19:17 PM12/30/20
to cython...@googlegroups.com
You're going to have to recompile your library with fpic to be able to build it as a shared library (and use it as a Python extension module).

--

---
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/55c546e9-ceed-4750-9355-c80969e9f445n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages