Using OSQP in C with R/Python package as dependency

101 views
Skip to first unread message

david.cor...@gmail.com

unread,
Dec 10, 2018, 12:50:19 PM12/10/18
to OSQP
I would like to use OSQP in a C file that is meant to be wrapped in R and Python (and uploaded to CRAN and PyPI), and I’m wondering what would be the best way of accomplishing this using the OSQP packages in CRAN and PyPI as dependencies rather than a system install of OSQP library.

My first thought was to include all header files from OSQP in the package, generate osqp_configure.h and qdldl_types.h, and link to the shared object that the CRAN/PyPI install generates, but the demo example from https://osqp.org/docs/examples/demo.html#c will segfault if I try that with the R shared object, and throw errors about not finding Python symbols with the Python shared object.

Ideally, I would like to use the OSQP C api directly rather than use Rcpp/Cython to call the R/Python functions which in turn would call the C functions. I think this can be done on Python by adding the OSQP binaries in a wheel and putting the headers in the package, but for R this would not be possible.

Any suggestions on how to create R/Python packages with C code that links to OSQP taking only the CRAN package as dependency?

harr...@mobike.com

unread,
Dec 11, 2018, 3:08:13 AM12/11/18
to OSQP
I wish to install the R package directly through `install.pacakges("osqp")` without any other extra efforts.

Goran Banjac

unread,
Dec 11, 2018, 3:16:13 AM12/11/18
to OSQP
For guidelines on how to install OSQP as an R package, please have a look at the OSQP documentation webpage:

Goran

Goran Banjac

unread,
Dec 11, 2018, 3:24:34 AM12/11/18
to OSQP
What is wrong about using precompiled OSQP libraries in both cases instead of PyPI or CRAN packages? You could then call C functions directly, and then wrap everything into a Python or R package.

An alternative would be to use OSQP through its Python and R interfaces.

Goran

david.cor...@gmail.com

unread,
Dec 11, 2018, 1:39:57 PM12/11/18
to OSQP
For PyPI - nothing wrong with that approach, but for CRAN, the problem is that it wouldn't then be possible to install through `install.packages` without requiring the user to also install OSQP outside of R, as CRAN doesn't allow embedding binaries in the same way as PyPI with python wheels.

From your answer, I'm guessing then that there isn't an easy way to call the C functions by linking against the shared object generated by a CRAN install, and the alternative would be to call the R functions through Rcpp.

宗宝冯

unread,
Apr 4, 2019, 3:13:58 AM4/4/19
to OSQP
在 2018年12月11日星期二 UTC+8下午4:16:13,Goran Banjac写道:
thank you
Reply all
Reply to author
Forward
0 new messages