Code works when run as a file, but not from REPL

I have a small piece of code which works perfectly when run as julia tmp.jl and even as julia -e 'include("tmp.jl")', but not when I start julia and immediately type include("tmp.jl")! Neither it works if I just copy-paste the content of tmp.jl into fresh julia session.
Namely, it fails with ERROR: LoadError: StackOverflowError: without traceback. So I have no idea how to debug it further from the julia side.
The code uses ccall and @cfunction with $closures to call a C/Fortran library, so I inserted a bunch of prints there for debug. They indicate that the library fails to call a function passed from julia as @cfunction, and again not sure how to debug further.

Unfortunately, I cannot provide a simple self-contained example now, as it uses both julia and c/fortran libraries.

At least show us the Julia code. Are you sure there is no recursive call?

Completely sure. The code in tmp.jl is very short and everything it does is calling a library:

using LibProcessTmp
    callback = (a, b) -> a == b,
    settings = Settings(size = 2),

I don’t see anything here to behave differently when run as a file and from repl. Also note, that the execution certainly goes into the library, and even into the wrapped C library, because I inserted prints there. And @cfunctions I talk about are defined in the library, not even in this tmp.jl file.

Sounds a bit like Initialization of R fails on julia 1.1

Any idea how to debug this?