# problem with ccall in v1.0

**URL:** https://discourse.julialang.org/t/problem-with-ccall-in-v1-0/15869
**Category:** New to Julia
**Created:** [October 4, 2018, 11:55am UTC](https://discourse.julialang.org/t/problem-with-ccall-in-v1-0/15869 "2018-10-04T11:55:38Z")
**Posts on this page:** 5
**Page:** 2

<div class="post-metadata">

### Author: ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)
#### Post date: [October 11, 2018, 4:54am UTC](https://discourse.julialang.org/t/problem-with-ccall-in-v1-0/15869/21 "2018-10-11T04:54:07Z")

</div>

> [@pixelate](#):
>
> Shared libraries and functions are referenced by a tuple of the form `(:function, "library")`

Where? What I see in doc is this:

> [`ccall`](https://docs.julialang.org/en/v1/base/c/#ccall) — Keyword.
> 
> ```julia
> ccall((function_name, library), returntype, (argtype1, ...), argvalue1, ...)
> ccall(function_pointer, returntype, (argtype1, ...), argvalue1, ...)
> 
> ```
> 
> Call a function in a C-exported shared library, specified by the tuple `(function_name, library)` , where each  
> component is either a string or symbol. Alternatively, `ccall` may also be used to call a function pointer  
> `function_pointer` , such as one returned by `dlsym` .
> 
> Note that the argument type tuple must be a literal tuple, and not a tuple-valued variable or expression.
> 
> Each `argvalue` to the `ccall` will be converted to the corresponding `argtype` , by automatic insertion of calls to `unsafe_convert(argtype, cconvert(argtype, argvalue))` . (See also the documentation for [`unsafe_convert`](https://docs.julialang.org/en/v1/base/c/#Base.unsafe_convert) and [`cconvert`](https://docs.julialang.org/en/v1/base/c/#Base.cconvert) for further details.) In most cases, this simply results in a call to `convert(argtype, argvalue)` .

---

<div class="post-metadata">

### Author: ![pixelate](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@pixelate](https://discourse.julialang.org/u/pixelate)
#### Post date: [October 11, 2018, 10:59am UTC](https://discourse.julialang.org/t/problem-with-ccall-in-v1-0/15869/22 "2018-10-11T10:59:34Z")

</div>

The lines

```julia
  lib = "./libtest.so"
  v = ccall((:test,lib),Int32,())

```

lead to a segfault that terminates the REPL that leaves me back at the shell command line.

The line

```julia
  v = ccall((:test,"./libtest.so"),Int32,())

```

works perfectly.

The docementation on [Calling C and Fortran Code · The Julia Language](https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code)  
says that the argument to `ccall` should be of the form `(:function, "library")`

If anyone finds it useful then the complete output given by Julia when it hits this bug and segfaults is:

```julia
julia> iinclude("m.jl")
hello

signal (11): Segmentation fault
in expression starting at /tcenas/home/anderson/julia/xxx/m.jl:13
_ZN4llvm3Use3setEPNS_5ValueE at /usr/local/bin/julia-1.0.1/bin/../lib/julia/libLLVM-6.0.so (unknown line)
_ZN4llvm8LoadInstC2EPNS_4TypeEPNS_5ValueEPKcbPNS_11InstructionE at /usr/local/bin/julia-1.0.1/bin/../lib/julia/libLLVM-6.0.so (unknown line)
CreateLoad at /buildworker/worker/package_linux64/build/usr/include/llvm/IR/IRBuilder.h:1175
emit_varinfo at /buildworker/worker/package_linux64/build/src/codegen.cpp:3374
emit_expr at /buildworker/worker/package_linux64/build/src/codegen.cpp:3455
emit_call at /buildworker/worker/package_linux64/build/src/codegen.cpp:3140
emit_expr at /buildworker/worker/package_linux64/build/src/codegen.cpp:3902
interpret_symbol_arg at /buildworker/worker/package_linux64/build/src/ccall.cpp:675
emit_ccall at /buildworker/worker/package_linux64/build/src/ccall.cpp:1523
emit_expr at /buildworker/worker/package_linux64/build/src/codegen.cpp:3912
emit_ssaval_assign at /buildworker/worker/package_linux64/build/src/codegen.cpp:3615
emit_stmtpos at /buildworker/worker/package_linux64/build/src/codegen.cpp:3801 [inlined]
emit_function at /buildworker/worker/package_linux64/build/src/codegen.cpp:6254
jl_compile_linfo at /buildworker/worker/package_linux64/build/src/codegen.cpp:1159
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1796
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:324
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:430
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:363 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:682
jl_interpret_toplevel_thunk_callback at /buildworker/worker/package_linux64/build/src/interpreter.c:795
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7f20528e4aff)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:804
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:813
jl_parse_eval_all at /buildworker/worker/package_linux64/build/src/ast.c:838
jl_load at /buildworker/worker/package_linux64/build/src/toplevel.c:847
include at ./boot.jl:317 [inlined]
include_relative at ./loading.jl:1041
include at ./sysimg.jl:29
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
include at ./client.jl:388
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:324
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:430
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:363 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:682
jl_interpret_toplevel_thunk_callback at /buildworker/worker/package_linux64/build/src/interpreter.c:795
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7f20528e419f)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:804
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:813
jl_toplevel_eval_in at /buildworker/worker/package_linux64/build/src/builtins.c:622
eval at ./boot.jl:319
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
eval_user_input at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:85
macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:117 [inlined]
#28 at ./task.jl:259
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1537 [inlined]
start_task at /buildworker/worker/package_linux64/build/src/task.c:268
unknown function (ip: 0xffffffffffffffff)
Allocations: 132634 (Pool: 132568; Big: 66); GC: 0
Segmentation fault (core dumped)
>

```

But I now understand the cause of the problem and can work around it, so I can only suggest that the error trapping inside `ccall` is improved to avoid anyone else getting coming across this issue.

Now I can push on with upgrading the interface to my library from 6.4 to 1.0 and see what other problems I can find 🙂

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [October 11, 2018, 12:06pm UTC](https://discourse.julialang.org/t/problem-with-ccall-in-v1-0/15869/23 "2018-10-11T12:06:32Z")

</div>

Julia shouldn’t segfault in this case. Since you have such a nice simple reproducible example, I would suggest opening a Julia issue so that this can get fixed.

---

<div class="post-metadata">

### Author: ![pixelate](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@pixelate](https://discourse.julialang.org/u/pixelate)
#### Post date: [October 11, 2018, 4:39pm UTC](https://discourse.julialang.org/t/problem-with-ccall-in-v1-0/15869/24 "2018-10-11T16:39:27Z")

</div>

A Julia issue has now been opened:  
[https://github.com/JuliaLang/julia/issues/29602](https://github.com/JuliaLang/julia/issues/29602)

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [October 11, 2018, 5:11pm UTC](https://discourse.julialang.org/t/problem-with-ccall-in-v1-0/15869/25 "2018-10-11T17:11:59Z")

</div>

Thank you!

[Previous page](https://discourse.julialang.org/t/problem-with-ccall-in-v1-0/15869.md?page=1)
