# Can't load a shared library

**URL:** <https://discourse.julialang.org/t/cant-load-a-shared-library/98621>\
**Category:** General Usage\
**Tags:** ccall\
**Created:** [May 10, 2023, 2:47pm UTC](https://discourse.julialang.org/t/cant-load-a-shared-library/98621 "2023-05-10T14:47:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nebula](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nebula/32/18214_2.png) [@nebula](https://discourse.julialang.org/u/nebula)\
**Post date:** [May 10, 2023, 2:47pm UTC](https://discourse.julialang.org/t/cant-load-a-shared-library/98621/1 "2023-05-10T14:47:45Z")

</div>

I have a shared library liba.so which requires /lib/x86\_64-linux-gnu/libcurl.so to run.

```julia
bash> ldd liba.so
...
libcurl.so.4 => /lib/x86_64-linux-gnu/libcurl.so.4 (0x00007f319ee74000)
...

```

I use ccall to call a function in liba.so, but it produces an error below:

```julia
ERROR: could not load library "/home/xxx/.../lib/liba.so"
/home/xxx/julia/bin/../lib/julia/libcurl.so: version `CURL_OPENSSL_4' not found (required by /home/xxx/.../lib/liba.so)

```

It seems that the required shared library is linked to the libcurl.so provided by Julia. What should I do to load the shared library liba.so?

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [May 11, 2023, 4:04am UTC](https://discourse.julialang.org/t/cant-load-a-shared-library/98621/2 "2023-05-11T04:04:12Z")

</div>

You may be able to fix this by setting the `rpath` for your library, either in the link stage of building it or with `patchelf`. I once asserted that this sort of thing would not work, but @staticfloat has made admirable steps towards proving me wrong, so perhaps he can provide more complete advice.

---

<div class="post-metadata">

**Author:** ![nebula](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nebula/32/18214_2.png) [@nebula](https://discourse.julialang.org/u/nebula)\
**Post date:** [May 11, 2023, 6:43am UTC](https://discourse.julialang.org/t/cant-load-a-shared-library/98621/3 "2023-05-11T06:43:16Z")

</div>

Thank you for reply. I run `patchelf --set-rpath /lib/x86_64-linux-gnu liba.so`, and the same error occurs.  
I provide a simple example here.  
The file `a.c`:

```cc
#include <stdio.h>
#include <curl/curl.h>
void test()
{
  printf("%s\n", curl_version());
}

```

and compile it with `gcc -shared -fPIC a.c -lcurl -Wl,-rpath=/lib/x86_64-linux-gnu -o liba.so`  
In Julia, I run `Libc.Libdl.dlopen("liba.so")`, and throw the above error still:

```julia
ERROR: could not load library "liba.so"
/home/xxx/julia/bin/../lib/julia/libcurl.so: version `CURL_OPENSSL_4' not found (required by liba.so)

```

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [May 13, 2023, 6:18pm UTC](https://discourse.julialang.org/t/cant-load-a-shared-library/98621/4 "2023-05-13T18:18:41Z")

</div>

I experimented a bit but haven’t been able to get runpath/deepbind to work as advertised (IIUC) for this case either.

Another approach is to use the environment variable `LD_PRELOAD=/lib/x86_64-linux-gnu/libcurl.so` in the shell where you run Julia (and hope that nothing in your Julia environment really needs, or pointlessly checks for, the other version if it can’t find it).

But the most robust solution (if you have the time to work it out) would probably be to compile your library using BinaryBuilder so that it has a better chance at portable compatibility.

---

<div class="post-metadata">

**Author:** ![nebula](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nebula/32/18214_2.png) [@nebula](https://discourse.julialang.org/u/nebula)\
**Post date:** [May 14, 2023, 2:58am UTC](https://discourse.julialang.org/t/cant-load-a-shared-library/98621/5 "2023-05-14T02:58:25Z")

</div>

Thank you. It works fine after I modify the environment variable `LD_PRELOAD`.

I compare the output with that calling from Python’s `ctypes`, and they are equal. There seems no bug.
