How to dynamically link against jemalloc

My rust program dlopen a shared library written in C during runtime.
I was hoping to make rust dynamically link against libjemalloc.so.
The motive is to make the C shared library call jemalloc's malloc and free.
So far I've only found a static way, which does not meet my requirement.
My environment is ubuntu 20.04 on x86_64.

You can pass in linker flags with the link-args. One way to do it would be to use a "cargo config file".
You can see here for an example. You would probably want to do something like link-args=-l jemalloc.
Then, you can define the functions you want to call in extern blocks.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.