# Cannot use shared library with Distributed.jl

**URL:** <https://discourse.julialang.org/t/cannot-use-shared-library-with-distributed-jl/139833>\
**Category:** General Usage\
**Tags:** ccall, distributed\
**Created:** [October 5, 2026, 11:55am UTC](https://discourse.julialang.org/t/cannot-use-shared-library-with-distributed-jl/139833 "2026-10-05T11:55:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alseidon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alseidon/32/207775_2.png) [@Alseidon](https://discourse.julialang.org/u/Alseidon)\
**Post date:** [October 5, 2026, 11:55am UTC](https://discourse.julialang.org/t/cannot-use-shared-library-with-distributed-jl/139833/1 "2026-10-05T11:55:40Z")

</div>

Hi,  
I’m trying to use a shared library in a `pmap` call from [Distributed.jl](https://github.com/JuliaLang/Distributed.jl), but can’t seem to make it work.

MWE:  
A file `mylib.c` with this:

```C
#include <stdio.h>

int say_y(int y)
{
    printf("Hello from C: got y = %d.\n", y);
    return y*2;
}

```

and the julia code:

```julia-auto
using Distributed, Libdl
addprocs()
run(`gcc -fPIC -shared -o mylib.so mylib.c`)

@everywhere function get_dlhandler()
    lib = Libdl.dlopen(joinpath(@ __DIR__ , "mylib.so"))
    symbol = Libdl.dlsym(lib, :say_y)
    return (lib, symbol)
end

@everywhere lib, symbol = get_dlhandler()

map(id->fetch(@spawnat id lib), 1:nprocs())
#=
All pointers but the first are undefined: 
 Ptr{Nothing}(0x000000003ceccb50)
 Ptr{Nothing}(0x0000000000000000)
 Ptr{Nothing}(0x0000000000000000)
 ...
=#

```

I also tried having a different copy of the shared library `mylib.so` for each process, without any change.

There must be something I don’t grasp about distributed computing, shared libraries and filesystem interaction, but I can’t seem to find an answer. Any idea as to what I’m doing wrong?

PS: using the library with `@ccall` works, but I want to keep the library reference in order to avoid opening it again and again:

```julia-auto
pmap(y->(@ccall "./mylib.so".say_y(y::Cint)::Cint), 1:10)
# returns [2, 4, 6,..., 20]

```
