# Should \`dlopen\` not first search the libraries loaded already like \`dllist\` ones?

**URL:** https://discourse.julialang.org/t/should-dlopen-not-first-search-the-libraries-loaded-already-like-dllist-ones/25719
**Category:** Internals & Design
**Created:** [June 26, 2019, 1:14pm UTC](https://discourse.julialang.org/t/should-dlopen-not-first-search-the-libraries-loaded-already-like-dllist-ones/25719 "2019-06-26T13:14:45Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![sambitdash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sambitdash/32/1377_2.png) [@sambitdash](https://discourse.julialang.org/u/sambitdash)
#### Post date: [June 26, 2019, 1:14pm UTC](https://discourse.julialang.org/t/should-dlopen-not-first-search-the-libraries-loaded-already-like-dllist-ones/25719/1 "2019-06-26T13:14:45Z")

</div>

Hi All,

I am trying to search for `libc` so that I can pass the `malloc` function to a library.

```julia
julia> dlopen("libc")
ERROR: could not load library "libc"
/usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header
Stacktrace:
 [1] #dlopen#3(::Bool, ::Function, ::String, ::UInt32) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Libdl/src/Libdl.jl:109
 [2] dlopen at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Libdl/src/Libdl.jl:109 [inlined] (repeats 2 times)
 [3] top-level scope at none:0

```

while `dllist` gives me a different libc is loaded.

```julia
julia> dllist()
28-element Array{AbstractString,1}:
 "linux-vdso.so.1"                                                                  
 "/home/sambit/julia-install/julia-1.1.0/bin/../lib/libjulia.so.1"                  
 "/lib/x86_64-linux-gnu/libdl.so.2"                                                 
 "/lib/x86_64-linux-gnu/librt.so.1"                                                 
 "/lib/x86_64-linux-gnu/libpthread.so.0"                                            
 "/lib/x86_64-linux-gnu/libc.so.6"         

```

Should `/lib/x86_64-linux-gnu/libc.so.6` not be loaded by `dlopen` in the first place?

regards,

Sambit

---

<div class="post-metadata">

### Author: ![mwolff](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@mwolff](https://discourse.julialang.org/u/mwolff)
#### Post date: [June 27, 2019, 9:15am UTC](https://discourse.julialang.org/t/should-dlopen-not-first-search-the-libraries-loaded-already-like-dllist-ones/25719/2 "2019-06-27T09:15:36Z")

</div>

Instead of “libc” you should use “libc.so.6” then it should work.

best regards

Michael

---

<div class="post-metadata">

### Author: ![sambitdash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sambitdash/32/1377_2.png) [@sambitdash](https://discourse.julialang.org/u/sambitdash)
#### Post date: [June 27, 2019, 1:33pm UTC](https://discourse.julialang.org/t/should-dlopen-not-first-search-the-libraries-loaded-already-like-dllist-ones/25719/3 "2019-06-27T13:33:47Z")

</div>

Will check that. But that may be a bit platform specific.

regards,

Sambit

---

<div class="post-metadata">

### Author: ![sambitdash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sambitdash/32/1377_2.png) [@sambitdash](https://discourse.julialang.org/u/sambitdash)
#### Post date: [June 27, 2019, 1:58pm UTC](https://discourse.julialang.org/t/should-dlopen-not-first-search-the-libraries-loaded-already-like-dllist-ones/25719/4 "2019-06-27T13:58:17Z")

</div>

```julia
julia> dlopen("libc.so.6")
Ptr{Nothing} @0x00007fbe7ec7b400

```

works. But I am not fully convinced if this is the right approach. Is the `libc6` kind of standard on all Unix platforms Julia supports? In that case it’s fine.

regards,

Sambit

---

<div class="post-metadata">

### Author: ![sambitdash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sambitdash/32/1377_2.png) [@sambitdash](https://discourse.julialang.org/u/sambitdash)
#### Post date: [June 27, 2019, 2:08pm UTC](https://discourse.julialang.org/t/should-dlopen-not-first-search-the-libraries-loaded-already-like-dllist-ones/25719/5 "2019-06-27T14:08:52Z")

</div>

I would assume `libc6` is kind of default. Libc 2-5 were released in 90s.

> **[glibc](https://en.wikipedia.org/wiki/GNU_C_Library)**
>
> The GNU C Library, commonly known as glibc, is the GNU Project's implementation of the C standard library. Despite its name, it now also directly supports C++ (and, indirectly, other programming languages). It was started in the 1980s by the Free Software Foundation (FSF) for the GNU operating system.
> Released under the GNU Lesser General Public License, glibc is free software. The GNU C Library project provides the core libraries for the GNU system, as well as many systems that use Linux as t...

regards,

Sambit

---

<div class="post-metadata">

### Author: ![mwolff](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@mwolff](https://discourse.julialang.org/u/mwolff)
#### Post date: [June 28, 2019, 9:13am UTC](https://discourse.julialang.org/t/should-dlopen-not-first-search-the-libraries-loaded-already-like-dllist-ones/25719/6 "2019-06-28T09:13:01Z")

</div>

On my laptop with Lubuntu 16.04 libc.so.6 is a link to libc-2.23.so.

best regards

Michael

---

<div class="post-metadata">

### Author: ![sambitdash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sambitdash/32/1377_2.png) [@sambitdash](https://discourse.julialang.org/u/sambitdash)
#### Post date: [June 28, 2019, 9:55am UTC](https://discourse.julialang.org/t/should-dlopen-not-first-search-the-libraries-loaded-already-like-dllist-ones/25719/7 "2019-06-28T09:55:21Z")

</div>

@mwolff,

There is `libc` as POSIX standard library version and there glibc which is the GNU libc version. The libc-2.23.so is the glibc version. We cannot rely on that one much as that may vary from system to system.

`glibc-2.x` is all `libc6`.

```julia
sambit@ubutubu:/lib/x86_64-linux-gnu$ ls -l *libc*
-rwxr-xr-x 1 root root 2030544 Apr 17 2018 libc-2.27.so
...
lrwxrwxrwx 1 root root 12 Apr 17 2018 libc.so.6 -> libc-2.27.so

```

regards,

Sambit

---

<div class="post-metadata">

### Author: ![mwolff](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@mwolff](https://discourse.julialang.org/u/mwolff)
#### Post date: [June 28, 2019, 10:06am UTC](https://discourse.julialang.org/t/should-dlopen-not-first-search-the-libraries-loaded-already-like-dllist-ones/25719/8 "2019-06-28T10:06:32Z")

</div>

> [@sambitdash](#):
>
> We cannot rely on that one much as that may vary from system to system.

As far as I know, a new version of libc only changes the link from libc.so.6 to the new version. Or you can create your own local link to the latest version.

best regards

Michael
