# BinaryBuilder for Deldir

**URL:** <https://discourse.julialang.org/t/binarybuilder-for-deldir/24120>\
**Category:** Tooling\
**Created:** [May 11, 2019, 9:16pm UTC](https://discourse.julialang.org/t/binarybuilder-for-deldir/24120 "2019-05-11T21:16:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertdj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robertdj/32/103_2.png) [@robertdj](https://discourse.julialang.org/u/robertdj)\
**Post date:** [May 11, 2019, 9:16pm UTC](https://discourse.julialang.org/t/binarybuilder-for-deldir/24120/1 "2019-05-11T21:16:34Z")

</div>

I’m trying out BinaryBuilder for my [Deldir](https://github.com/robertdj/Deldir.jl) package that wraps Fortran code from the R package deldir.

On my own computer I can create a working shared object file with the following Bash commands extracted from the R package:

```julia
for f in `ls *.f | sed "s/\.f$//"`; do
    gfortran -fpic -o2 -pipe -g -c $f.f -o $f.o
done

clang -shared -o libdeldir.so *.o -lgfortran -lm -lquadmath

```

In fact, I don’t even need the last three `-l` commands.

When running something similar with BinaryBuilder I get no compilation errors, but `ccall`’ing `libdeldir.so` make Julia segfault.  
Even after a lot of searching and trying different compiler tricks I have no luck in creating a working `so` file.  
With the lack of compilation errors I don’t really know how to move forward,

I have made a [DeldirBuilder](https://github.com/robertdj/DeldirBuilder) repo with the `build_tarballs.jl` script.  
For easy reference, my Bash script for compilation is

```julia
for f in `ls *.f | sed "s/\.f$//"`; do
    ${FC} -fpic -o2 -pipe -g -c $f.f -o $f.o
done

mkdir -p "${prefix}/lib"
LDFLAGS="-lgfortran -lm -lquadmath"
${CC} -shared -o ${prefix}/lib/libdeldir.${dlext} *.o 

```

BTW I _do_ get errors with older versions of GCC, but e.g. GCC 7 is okay:

```julia
julia --color=yes build_tarballs.jl --verbose --debug x86_64-linux-gnu-gcc7

```

I have asked a similar question on the bindeps2 channel on Slack. Sorry for crosspostning, but I haven’t succeeded with the suggestions I got there.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [May 11, 2019, 11:03pm UTC](https://discourse.julialang.org/t/binarybuilder-for-deldir/24120/2 "2019-05-11T23:03:29Z")

</div>

I don’t know if this fixes the issue, but you’re not using the `LDFLAGS` variable after you set it.

Also, the script that you show here is different from what it’s [now on GitHub](https://github.com/robertdj/DeldirBuilder/blob/01a638af4ea4ceb8209b1f1a0c38e7ac3d35315f/build_tarballs.jl), for example there you don’t create the `$prefix/lib` directory (which leads to an error when you try to compile and put the output there).

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [May 11, 2019, 11:31pm UTC](https://discourse.julialang.org/t/binarybuilder-for-deldir/24120/3 "2019-05-11T23:31:12Z")

</div>

Anyway, even without using `LDFLAGS` at all, I cannot reproduce your segmentation fault (64-bit GNU/Linux systems here). I’m trying to build the library with the following script:

```julia
script = raw"""
cd $WORKSPACE/srcdir/deldir/src

for f in `ls *.f | sed "s/\.f$//"`; do
    ${FC} -fpic -o2 -pipe -g -c $f.f -o $f.o
done

mkdir -p "${prefix}/lib"
${CC} -shared -o ${prefix}/lib/libdeldir.${dlext} *.o
"""

```

The rest of the `build_tarballs.jl` is the one on GitHub. I then copy the resulting `libdeldir.so` to `deps/deldir.so` in the Julia package directory and run the tests. I get the following error:

```julia
ERROR: LoadError: InexactError: trunc(Int32, 100)
Stacktrace:
 [1] throw_inexacterror(::Symbol, ::Any, ::Int64) at ./boot.jl:583
 [2] checked_trunc_sint at ./boot.jl:605 [inlined]
 [3] toInt32 at ./boot.jl:642 [inlined]
 [4] Type at ./boot.jl:732 [inlined]
 [5] convert at ./number.jl:7 [inlined]
 [6] Type at ./refvalue.jl:8 [inlined]
 [7] convert at ./refpointer.jl:51 [inlined]
 [8] cconvert at ./essentials.jl:355 [inlined]
 [9] #deldirwrapper#1(::Float64, ::Function, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}) at /home/mose/.julia/dev/Deldir/src/wrapper.jl:151
 [10] deldirwrapper at /home/mose/.julia/dev/Deldir/src/wrapper.jl:141 [inlined]
 [11] voronoiarea at /home/mose/.julia/dev/Deldir/src/misc.jl:9 [inlined] (repeats 2 times)
 [12] top-level scope at none:0
 [13] include at ./boot.jl:326 [inlined]
 [14] include_relative(::Module, ::String) at ./loading.jl:1038
 [15] include(::Module, ::String) at ./sysimg.jl:29
 [16] include(::String) at ./client.jl:403
 [17] top-level scope at none:0
in expression starting at /home/mose/.julia/dev/Deldir/test/runtests.jl:9
ERROR: Package Deldir errored during testing

```

> [@robertdj](#):
>
> BTW I _do_ get errors with older versions of GCC, but e.g. GCC 7 is okay:

Older compared to what? The default compiler on GNU/Linux systems with BinaryBuilder is GCC 4.

---

<div class="post-metadata">

**Author:** ![robertdj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robertdj/32/103_2.png) [@robertdj](https://discourse.julialang.org/u/robertdj)\
**Post date:** [May 12, 2019, 8:11pm UTC](https://discourse.julialang.org/t/binarybuilder-for-deldir/24120/4 "2019-05-12T20:11:46Z")

</div>

Thanks a lot for trying it out – it’s super weird that it works for you.

Sorry about the mismatch between the posted script and the one on GitHub! When experimenting I _did_ create the `lib` folder.

Now that I think about it I suppose the segfault can be caused by using a wrong architecture. I use “x86\_64-linux-gnu” since this is in “OS” of `versioninfo`:

```julia
julia> versioninfo()
Julia Version 1.1.0
Commit 80516ca202* (2019-01-21 21:24 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)

```

Have I understood this correctly?

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [May 12, 2019, 8:21pm UTC](https://discourse.julialang.org/t/binarybuilder-for-deldir/24120/5 "2019-05-12T20:21:12Z")

</div>

Yes, your platform (and also mine) is “x86\_64-linux-gnu”, you should create the build for that platform if you want to test locally

PS:

```bash
for f in `ls *.f | sed "s/\.f$//"`; do
  ${FC} -fpic -o2 -pipe -g -c $f.f -o $f.o
done

```

is better written as

```bash
for f in *.f; do
  ${FC} -fpic -o2 -pipe -g -c "${f}" -o "$(basename "${f}" .f}.o"
done

```

It’s [discouraged](https://mywiki.wooledge.org/ParsingLs) to use the output of `ls`

---

<div class="post-metadata">

**Author:** ![robertdj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robertdj/32/103_2.png) [@robertdj](https://discourse.julialang.org/u/robertdj)\
**Post date:** [May 12, 2019, 8:24pm UTC](https://discourse.julialang.org/t/binarybuilder-for-deldir/24120/6 "2019-05-12T20:24:10Z")

</div>

I’ll give it another go tomorrow – thanks a lot for you help!  
Also thanks for the bash tips 🙂

Regarding the compiler version I meant compared to the default version 4. But since that also works for you I suppose it’s not a real problem.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [May 12, 2019, 8:25pm UTC](https://discourse.julialang.org/t/binarybuilder-for-deldir/24120/7 "2019-05-12T20:25:28Z")

</div>

> [@robertdj](#):
>
> But since that also works for you I suppose it’s not a real problem.

“works” in the sense that I don’t get the segmentation fault, but the test fails because of the error posted above.

---

<div class="post-metadata">

**Author:** ![robertdj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robertdj/32/103_2.png) [@robertdj](https://discourse.julialang.org/u/robertdj)\
**Post date:** [May 15, 2019, 8:18pm UTC](https://discourse.julialang.org/t/binarybuilder-for-deldir/24120/8 "2019-05-15T20:18:19Z")

</div>

I think I have found out why we get different results: The tests did not get to the `ccall` (now I have updated them so they do).  
@giordano : Does your `so` file work with the following commands?

```julia
using Deldir
x = rand(8); y = rand(8);
A = voronoiarea(x, y)

```

I get this segfault

```julia
signal (11): Segmentation fault [9/885]
in expression starting at /home/robert/.julia/dev/Deldir/startup.jl:9
unsafe_convert at ./pointer.jl:65 [inlined]
pointer at ./abstractarray.jl:883 [inlined]
unsafe_convert at ./refpointer.jl:66 [inlined]
unsafe_convert at ./refpointer.jl:48 [inlined]
#deldirwrapper#1 at /home/robert/.julia/dev/Deldir/src/wrapper.jl:151
unknown function (ip: 0x7f11fc8d3008)
jl_fptr_trampoline at /usr/local/julia/julia-1.1.0/src/gf.c:1864
jl_apply_generic at /usr/local/julia/julia-1.1.0/src/gf.c:2219
deldirwrapper at /home/robert/.julia/dev/Deldir/src/wrapper.jl:141 [inlined]
voronoiarea at /home/robert/.julia/dev/Deldir/src/misc.jl:9 [inlined]
voronoiarea at /home/robert/.julia/dev/Deldir/src/misc.jl:9
jl_fptr_trampoline at /usr/local/julia/julia-1.1.0/src/gf.c:1864
jl_apply_generic at /usr/local/julia/julia-1.1.0/src/gf.c:2219
do_call at /usr/local/julia/julia-1.1.0/src/interpreter.c:323
eval_value at /usr/local/julia/julia-1.1.0/src/interpreter.c:411
eval_stmt_value at /usr/local/julia/julia-1.1.0/src/interpreter.c:362 [inlined]
eval_body at /usr/local/julia/julia-1.1.0/src/interpreter.c:773
jl_interpret_toplevel_thunk_callback at /usr/local/julia/julia-1.1.0/src/interpreter.c:885
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7f11c102878f)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /usr/local/julia/julia-1.1.0/src/interpreter.c:894
jl_toplevel_eval_flex at /usr/local/julia/julia-1.1.0/src/toplevel.c:764
jl_parse_eval_all at /usr/local/julia/julia-1.1.0/src/ast.c:883
jl_load at /usr/local/julia/julia-1.1.0/src/toplevel.c:826
include at ./boot.jl:326 [inlined]
include_relative at ./loading.jl:1038
include at ./sysimg.jl:29
jl_fptr_trampoline at /usr/local/julia/julia-1.1.0/src/gf.c:1864
jl_apply_generic at /usr/local/julia/julia-1.1.0/src/gf.c:2219
include at ./client.jl:403
jl_fptr_trampoline at /usr/local/julia/julia-1.1.0/src/gf.c:1864
jl_apply_generic at /usr/local/julia/julia-1.1.0/src/gf.c:2219
do_call at /usr/local/julia/julia-1.1.0/src/interpreter.c:323
eval_value at /usr/local/julia/julia-1.1.0/src/interpreter.c:411
eval_stmt_value at /usr/local/julia/julia-1.1.0/src/interpreter.c:362 [inlined]
eval_body at /usr/local/julia/julia-1.1.0/src/interpreter.c:773
jl_interpret_toplevel_thunk_callback at /usr/local/julia/julia-1.1.0/src/interpreter.c:885
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7f11c01222bf)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /usr/local/julia/julia-1.1.0/src/interpreter.c:894
jl_toplevel_eval_flex at /usr/local/julia/julia-1.1.0/src/toplevel.c:764
jl_toplevel_eval_in at /usr/local/julia/julia-1.1.0/src/toplevel.c:793
eval at ./boot.jl:328
jl_apply_generic at /usr/local/julia/julia-1.1.0/src/gf.c:2219
eval_user_input at /usr/local/julia/julia-1.1.0/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:85
macro expansion at /usr/local/julia/julia-1.1.0/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:117 [inlined]
#26 at ./task.jl:259
jl_apply_generic at /usr/local/julia/julia-1.1.0/src/gf.c:2219
jl_apply at /usr/local/julia/julia-1.1.0/src/julia.h:1571 [inlined]
start_task at /usr/local/julia/julia-1.1.0/src/task.c:572
unknown function (ip: 0xffffffffffffffff)
Allocations: 31039849 (Pool: 31033213; Big: 6636); GC: 65
[1] 28866 segmentation fault julia

```

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [May 15, 2019, 9:17pm UTC](https://discourse.julialang.org/t/binarybuilder-for-deldir/24120/9 "2019-05-15T21:17:00Z")

</div>

I get a segfault, too. Are you sure function signature is correct?

**Edit** : I had a look at the `ccall` and it does look correct to me at a quick glance.

---

<div class="post-metadata">

**Author:** ![robertdj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robertdj/32/103_2.png) [@robertdj](https://discourse.julialang.org/u/robertdj)\
**Post date:** [May 16, 2019, 3:13pm UTC](https://discourse.julialang.org/t/binarybuilder-for-deldir/24120/10 "2019-05-16T15:13:49Z")

</div>

That turned out to be a spot on question! I am using different versions of the Fortran code in the DeldirBuilder and the Deldir repos 😳

A huge thank you @giordano ! I had starred myself blind at this problem.
