Difficulty in using ccall

I’m trying to wrap the LibRaw C library in Julia using Clang.jl to provide the .raw image support in Julia. The wrapping was done successfully to give me a .jl file, with julia functions calling all the respective C language functions as follows:

Next I wrote the code for decoding a .raw file as follows:

include("lib/LibRaw.jl")

function decode_image(filename::AbstractString)
    data = LibRaw.libraw_init(0)
    
    LibRaw.libraw_open_file(data, filename)
    LibRaw.libraw_unpack(data)
    # process decoded image data
    LibRaw.libraw_free_image(data)
    LibRaw.libraw_recycle(data)
    LibRaw.libraw_close(data)
    return data
end

filename = "test\\nikon\\Nikon-D4-Shotkit-2.NEF"
data = decode_image(filename)

But on running this code I’m getting the following error after a very long error messege:

ERROR: `ccall` requires the compiler
Stacktrace:
 [1] libraw_init(flags::Int64)
   @ Main.LibRaw d:\D_Drive_HP\ImageIO\libraw\lib\LibRaw.jl:737
 [2] decode_image(filename::AbstractString)
   @ Main d:\D_Drive_HP\ImageIO\libraw\librawtest.jl:5
 [3] top-level scope
   @ d:\D_Drive_HP\ImageIO\libraw\librawtest.jl:17

The complete error messege is:

Internal error: encountered unexpected error during compilation of decode_image:
TypeError(func=:ccall, context="", expected=Symbol, got=LibRaw)
ijl_type_error_rt at /cygdrive/c/buildbot/worker/package_win64/build/src\rtutils.c:119
ijl_type_error at /cygdrive/c/buildbot/worker/package_win64/build/src\rtutils.c:127
interpret_symbol_arg at /cygdrive/c/buildbot/worker/package_win64/build/src\ccall.cpp:611
emit_ccall at /cygdrive/c/buildbot/worker/package_win64/build/src\ccall.cpp:1280
emit_expr at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:4723
emit_ssaval_assign at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:4310
emit_stmtpos at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:4557 [inlined]
emit_function at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:7387
jl_emit_code at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:7722
jl_emit_codeinst at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:7767
_jl_compile_codeinst at /cygdrive/c/buildbot/worker/package_win64/build/src\jitlayers.cpp:119
jl_generate_fptr_impl at /cygdrive/c/buildbot/worker/package_win64/build/src\jitlayers.cpp:332
jl_compile_method_internal at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2081
jl_compile_method_internal at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2028 [inlined]
_jl_invoke at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2359 [inlined]
ijl_apply_generic at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2549
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
do_call at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:126
eval_value at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:215
eval_stmt_value at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:166 [inlined]
eval_body at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:594
jl_interpret_toplevel_thunk at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:750
top-level scope at d:\D_Drive_HP\ImageIO\libraw\librawtest.jl:17
jl_toplevel_eval_flex at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:906
jl_toplevel_eval_flex at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:850
ijl_toplevel_eval at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:915 [inlined]
ijl_toplevel_eval_in at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:965
eval at .\boot.jl:368 [inlined]
include_string at .\loading.jl:1428
include_string at .\loading.jl:1438
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
jl_f__call_latest at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:774
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
do_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:730
#invokelatest#2 at .\essentials.jl:729
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
do_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:730
invokelatest at .\essentials.jl:726
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
do_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:730
#inlineeval#71 at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:233       
inlineeval##kw at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:230 [inlined]
#66 at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:157
withpath at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\repl.jl:249
#65 at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:155
hideprompt at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\repl.jl:38
#64 at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:126
unknown function (ip: 000000005a887083)
with_logstate at .\logging.jl:511
with_logger at .\logging.jl:623 [inlined]
#63 at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:225
unknown function (ip: 000000005a885553)
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
jl_f__call_latest at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:774
#invokelatest#2 at .\essentials.jl:729 [inlined]
invokelatest at .\essentials.jl:726
unknown function (ip: 000000005a87d9c6)
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
do_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:730
macro expansion at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:34 [inlined]
#61 at .\task.jl:484
unknown function (ip: 000000005a864cf3)
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
start_task at /cygdrive/c/buildbot/worker/package_win64/build/src\task.c:931
Internal error: encountered unexpected error during compilation of libraw_init:
TypeError(func=:ccall, context="", expected=Symbol, got=LibRaw)
ijl_type_error_rt at /cygdrive/c/buildbot/worker/package_win64/build/src\rtutils.c:119
ijl_type_error at /cygdrive/c/buildbot/worker/package_win64/build/src\rtutils.c:127
interpret_symbol_arg at /cygdrive/c/buildbot/worker/package_win64/build/src\ccall.cpp:611
emit_ccall at /cygdrive/c/buildbot/worker/package_win64/build/src\ccall.cpp:1280
emit_expr at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:4723
emit_ssaval_assign at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:4310
emit_stmtpos at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:4557 [inlined]
emit_function at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:7387
jl_emit_code at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:7722
jl_emit_codeinst at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:7767
_jl_compile_codeinst at /cygdrive/c/buildbot/worker/package_win64/build/src\jitlayers.cpp:119
jl_generate_fptr_impl at /cygdrive/c/buildbot/worker/package_win64/build/src\jitlayers.cpp:332
jl_compile_method_internal at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2081
jl_compile_method_internal at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2028 [inlined]
_jl_invoke at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2359 [inlined]
ijl_apply_generic at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2549
decode_image at d:\D_Drive_HP\ImageIO\libraw\librawtest.jl:5
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
do_call at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:126
eval_value at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:215
eval_stmt_value at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:166 [inlined]
eval_body at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:594
jl_interpret_toplevel_thunk at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:750
top-level scope at d:\D_Drive_HP\ImageIO\libraw\librawtest.jl:17
jl_toplevel_eval_flex at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:906
jl_toplevel_eval_flex at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:850
ijl_toplevel_eval at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:915 [inlined]
ijl_toplevel_eval_in at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:965
eval at .\boot.jl:368 [inlined]
include_string at .\loading.jl:1428
include_string at .\loading.jl:1438
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
jl_f__call_latest at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:774
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
do_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:730
#invokelatest#2 at .\essentials.jl:729
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
do_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:730
invokelatest at .\essentials.jl:726
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
do_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:730
#inlineeval#71 at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:233       
inlineeval##kw at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:230 [inlined]
#66 at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:157
withpath at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\repl.jl:249
#65 at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:155
hideprompt at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\repl.jl:38
#64 at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:126
unknown function (ip: 000000005a887083)
with_logstate at .\logging.jl:511
with_logger at .\logging.jl:623 [inlined]
#63 at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:225
unknown function (ip: 000000005a885553)
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
jl_f__call_latest at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:774
#invokelatest#2 at .\essentials.jl:729 [inlined]
invokelatest at .\essentials.jl:726
unknown function (ip: 000000005a87d9c6)
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
do_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:730
macro expansion at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:34 [inlined]
#61 at .\task.jl:484
unknown function (ip: 000000005a864cf3)
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
start_task at /cygdrive/c/buildbot/worker/package_win64/build/src\task.c:931
Internal error: encountered unexpected error during compilation of libraw_init:
TypeError(func=:ccall, context="", expected=Symbol, got=LibRaw)
ijl_type_error_rt at /cygdrive/c/buildbot/worker/package_win64/build/src\rtutils.c:119
ijl_type_error at /cygdrive/c/buildbot/worker/package_win64/build/src\rtutils.c:127
interpret_symbol_arg at /cygdrive/c/buildbot/worker/package_win64/build/src\ccall.cpp:611
emit_ccall at /cygdrive/c/buildbot/worker/package_win64/build/src\ccall.cpp:1280
emit_expr at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:4723
emit_ssaval_assign at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:4310
emit_stmtpos at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:4557 [inlined]
emit_function at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:7387
jl_emit_code at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:7722
jl_emit_codeinst at /cygdrive/c/buildbot/worker/package_win64/build/src\codegen.cpp:7767
_jl_compile_codeinst at /cygdrive/c/buildbot/worker/package_win64/build/src\jitlayers.cpp:119
jl_generate_fptr_for_unspecialized_impl at /cygdrive/c/buildbot/worker/package_win64/build/src\jitlayers.cpp:380
jl_compile_method_internal at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2094
jl_compile_method_internal at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2028 [inlined]
_jl_invoke at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2359 [inlined]
ijl_apply_generic at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2549
decode_image at d:\D_Drive_HP\ImageIO\libraw\librawtest.jl:5
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
do_call at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:126
eval_value at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:215
eval_stmt_value at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:166 [inlined]
eval_body at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:594
jl_interpret_toplevel_thunk at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:750
top-level scope at d:\D_Drive_HP\ImageIO\libraw\librawtest.jl:17
jl_toplevel_eval_flex at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:906
jl_toplevel_eval_flex at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:850
ijl_toplevel_eval at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:915 [inlined]
ijl_toplevel_eval_in at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:965
eval at .\boot.jl:368 [inlined]
include_string at .\loading.jl:1428
include_string at .\loading.jl:1438
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
jl_f__call_latest at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:774
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
do_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:730
#invokelatest#2 at .\essentials.jl:729
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
do_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:730
invokelatest at .\essentials.jl:726
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
do_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:730
#inlineeval#71 at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:233       
inlineeval##kw at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:230 [inlined]
#66 at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:157
withpath at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\repl.jl:249
#65 at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:155
hideprompt at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\repl.jl:38
#64 at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:126
unknown function (ip: 000000005a887083)
with_logstate at .\logging.jl:511
with_logger at .\logging.jl:623 [inlined]
#63 at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:225
unknown function (ip: 000000005a885553)
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
jl_f__call_latest at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:774
#invokelatest#2 at .\essentials.jl:729 [inlined]
invokelatest at .\essentials.jl:726
unknown function (ip: 000000005a87d9c6)
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
do_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:730
macro expansion at c:\Users\Aditi Dey\.vscode\extensions\julialang.language-julia-1.38.2\scripts\packages\VSCodeServer\src\eval.jl:34 [inlined]
#61 at .\task.jl:484
unknown function (ip: 000000005a864cf3)
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1839 [inlined]
start_task at /cygdrive/c/buildbot/worker/package_win64/build/src\task.c:931
ERROR: `ccall` requires the compiler
Stacktrace:
 [1] libraw_init(flags::Int64)
   @ Main.LibRaw d:\D_Drive_HP\ImageIO\libraw\lib\LibRaw.jl:737
 [2] decode_image(filename::AbstractString)
   @ Main d:\D_Drive_HP\ImageIO\libraw\librawtest.jl:5
 [3] top-level scope
   @ d:\D_Drive_HP\ImageIO\libraw\librawtest.jl:17

I have Julia installed in my windows system and added to path. I’m using VS Code, and on running the test code, the code automatically runs in the Julia REPL. Hence I’m not able to understand what is going wrong. Can anyone please help?

Welcome to the Julia discourse! :slight_smile: (just saw that you’re new here)

I only took a quick look but the following should be the issue: In the Julia wrapper functions in your LibRaw.jl (Clang.jl output), you everywhere have @ccall LibRaw.funcname(...). This is probably wrong because LibRaw doesn’t refer to a library but the LibRaw module itself. Instead you should define libraw = "libraw" (or the path to the library) e.g. at the top of the LibRaw module and then use @ccall libraw.funcname(...) (note the lowercased libraw) everywhere.

See for example LIKWID.jl/LibLikwid.jl at main · JuliaPerf/LIKWID.jl · GitHub where I use liblikwid everywhere which is imported from the parent module and defined here.

Is the libraw library just somewhere on the system or provided via Libraw_jll.jl? If via the latter, Libraw_jll should already have a libraw variable that points to the (artefact) library:

julia> using LibRaw_jll

julia> LibRaw_jll.libraw
"/Users/crstnbr/.julia/artifacts/89012ea5254391190eb51dc83bee6219ceaa6de0/lib/libraw.20.dylib"

MWE:

julia> module LibRaw end;

julia> @ccall LibRaw.asd()::Cvoid
Internal error: encountered unexpected error during compilation of top-level scope:
TypeError(func=:ccall, context="", expected=Symbol, got=LibRaw)
ijl_type_error_rt at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
ijl_type_error at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
_ZL20interpret_symbol_argR12jl_codectx_tR16native_sym_arg_tP11_jl_value_tPKcb at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
_ZL10emit_ccallR12jl_codectx_tPP11_jl_value_tm at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
_ZL9emit_exprR12jl_codectx_tP11_jl_value_tl at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
_ZL18emit_ssaval_assignR12jl_codectx_tlP11_jl_value_t at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
_ZL13emit_functionP21_jl_method_instance_tP15_jl_code_info_tP11_jl_value_tR20_jl_codegen_params_tRN4llvm11LLVMContextE at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
_Z12jl_emit_codeP21_jl_method_instance_tP15_jl_code_info_tP11_jl_value_tR20_jl_codegen_params_t at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
_Z16jl_emit_codeinstP19_jl_code_instance_tP15_jl_code_info_tR20_jl_codegen_params_t at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
_ZL20_jl_compile_codeinstP19_jl_code_instance_tP15_jl_code_info_tm at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
jl_generate_fptr_impl at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
jl_compile_method_internal at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
ijl_invoke at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
jl_toplevel_eval_flex at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
jl_toplevel_eval_flex at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
ijl_toplevel_eval_in at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
eval at ./boot.jl:368 [inlined]
eval_user_input at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-x64-4.0/build/default-macmini-x64-4-0/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:151
repl_backend_loop at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-x64-4.0/build/default-macmini-x64-4-0/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:247
start_repl_backend at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-x64-4.0/build/default-macmini-x64-4-0/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:232
#run_repl#47 at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-x64-4.0/build/default-macmini-x64-4-0/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:369
run_repl at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-x64-4.0/build/default-macmini-x64-4-0/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:355
jfptr_run_repl_65470.clone_1 at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/sys.dylib (unknown line)
ijl_apply_generic at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
#967 at ./client.jl:419
jfptr_YY.967_47614.clone_1 at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/sys.dylib (unknown line)
ijl_apply_generic at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
jl_f__call_latest at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
#invokelatest#2 at ./essentials.jl:729 [inlined]
invokelatest at ./essentials.jl:726 [inlined]
run_main_repl at ./client.jl:404
exec_options at ./client.jl:318
_start at ./client.jl:522
jfptr__start_28650.clone_1 at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/sys.dylib (unknown line)
ijl_apply_generic at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
true_main at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
jl_repl_entrypoint at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
Internal error: encountered unexpected error during compilation of top-level scope:
TypeError(func=:ccall, context="", expected=Symbol, got=LibRaw)
ijl_type_error_rt at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
ijl_type_error at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
_ZL20interpret_symbol_argR12jl_codectx_tR16native_sym_arg_tP11_jl_value_tPKcb at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
_ZL10emit_ccallR12jl_codectx_tPP11_jl_value_tm at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
_ZL9emit_exprR12jl_codectx_tP11_jl_value_tl at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
_ZL18emit_ssaval_assignR12jl_codectx_tlP11_jl_value_t at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
_ZL13emit_functionP21_jl_method_instance_tP15_jl_code_info_tP11_jl_value_tR20_jl_codegen_params_tRN4llvm11LLVMContextE at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
_Z12jl_emit_codeP21_jl_method_instance_tP15_jl_code_info_tP11_jl_value_tR20_jl_codegen_params_t at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
_Z16jl_emit_codeinstP19_jl_code_instance_tP15_jl_code_info_tR20_jl_codegen_params_t at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
_ZL20_jl_compile_codeinstP19_jl_code_instance_tP15_jl_code_info_tm at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
jl_generate_fptr_for_unspecialized_impl at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
jl_compile_method_internal at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
ijl_invoke at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
jl_toplevel_eval_flex at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
jl_toplevel_eval_flex at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
ijl_toplevel_eval_in at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
eval at ./boot.jl:368 [inlined]
eval_user_input at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-x64-4.0/build/default-macmini-x64-4-0/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:151
repl_backend_loop at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-x64-4.0/build/default-macmini-x64-4-0/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:247
start_repl_backend at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-x64-4.0/build/default-macmini-x64-4-0/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:232
#run_repl#47 at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-x64-4.0/build/default-macmini-x64-4-0/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:369
run_repl at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-x64-4.0/build/default-macmini-x64-4-0/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:355
jfptr_run_repl_65470.clone_1 at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/sys.dylib (unknown line)
ijl_apply_generic at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
#967 at ./client.jl:419
jfptr_YY.967_47614.clone_1 at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/sys.dylib (unknown line)
ijl_apply_generic at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
jl_f__call_latest at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
#invokelatest#2 at ./essentials.jl:729 [inlined]
invokelatest at ./essentials.jl:726 [inlined]
run_main_repl at ./client.jl:404
exec_options at ./client.jl:318
_start at ./client.jl:522
jfptr__start_28650.clone_1 at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/sys.dylib (unknown line)
ijl_apply_generic at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
true_main at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
jl_repl_entrypoint at /Users/crstnbr/.julia/juliaup/julia-1.8.4+0.x64.apple.darwin14/lib/julia/libjulia-internal.1.8.dylib (unknown line)
ERROR: `ccall` requires the compiler
Stacktrace:
 [1] Toplevel MethodInstance thunk
   @ Main REPL[2]:1

I wonder why the error is so cryptic. Sometimes we have nice errors:

julia> x = 3
3

julia> @ccall x.asd()::Cvoid
ERROR: TypeError: in ccall, expected Symbol, got a value of type Int64
Stacktrace:
 [1] top-level scope
   @ ./REPL[4]:1

Maybe worth filing an issue for properly catching the error and printing the same as for the above.

I did the exact same thing recently :slight_smile:

You can check in the gen folder for the Clang script I used. One issue I had was that I couldn’t unsafe_load a lot of the structs, Julia would just hang and crash if I try to interrupt it (not sure what’s going on there) so I had to resort to some pointer arithmetic to access the fields I needed.

Cool! Thankss to both of you :]