# \#ccall

**URL:** https://discourse.julialang.org/tag/ccall/38.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [How to pass a reference to a vector to C](https://discourse.julialang.org/t/how-to-pass-a-reference-to-a-vector-to-c/136320)

<div class="topic-metadata">

**Author:** [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Replies:** 2\
**Last updated:** [March 21, 2026, 2:18pm UTC](https://discourse.julialang.org/t/how-to-pass-a-reference-to-a-vector-to-c/136320 "2026-03-21T14:18:33Z")

</div>

I’m calling SimpleBLE which has an API where both the reading and writing functions take (uint8\_t\*\* data, size\_t\* data\_length) that are used to return data in the read case and pass data in the write case. My confusion …

---

## [Execute Function for each Julia Thread](https://discourse.julialang.org/t/execute-function-for-each-julia-thread/133889)

<div class="topic-metadata">

**Author:** [@Chrysoberyl](https://discourse.julialang.org/u/Chrysoberyl)\
**Replies:** 6\
**Last updated:** [November 15, 2025, 7:02am UTC](https://discourse.julialang.org/t/execute-function-for-each-julia-thread/133889 "2025-11-15T07:02:36Z")

</div>

I have an external library which requires thread local resources to function. For every thread Julia creates, it must notify this library via an initialize\_thread\_local() function. Is there a way to run this code for eac…

---

## [Dynamic Type in CxxWrap.jl](https://discourse.julialang.org/t/dynamic-type-in-cxxwrap-jl/133007)

<div class="topic-metadata">

**Author:** [@phK3](https://discourse.julialang.org/u/phK3)\
**Replies:** 1\
**Last updated:** [October 20, 2025, 9:56am UTC](https://discourse.julialang.org/t/dynamic-type-in-cxxwrap-jl/133007 "2025-10-20T09:56:31Z")

</div>

I want to use CxxWrap.jl to create a Julia wrapper for a C++ library. On the Julia side, I want to dispatch on the type of my arguments. But when using CxxWrap, the Julia side only seems to know about the static return…

---

## [Stack overflow when calling dynamic library requiring executable tack in the REPL](https://discourse.julialang.org/t/stack-overflow-when-calling-dynamic-library-requiring-executable-tack-in-the-repl/132027)

<div class="topic-metadata">

**Author:** [@HugoMVale](https://discourse.julialang.org/u/HugoMVale)\
**Replies:** 0\
**Last updated:** [September 1, 2025, 6:04pm UTC](https://discourse.julialang.org/t/stack-overflow-when-calling-dynamic-library-requiring-executable-tack-in-the-repl/132027 "2025-09-01T18:04:42Z")

</div>

I am writing bindings to a Fortran library. The bindings work perfectly when launched as “run file in new process”. Conversely, when launched directly from the REPL, a stack overflow error is raised, without further info…

---

## [\`IOStream\` buffering pitfalls when communicating to a device file](https://discourse.julialang.org/t/iostream-buffering-pitfalls-when-communicating-to-a-device-file/130071)

<div class="topic-metadata">

**Author:** [@Yuan-Ru-Lin](https://discourse.julialang.org/u/Yuan-Ru-Lin)\
**Replies:** 1\
**Last updated:** [August 4, 2025, 9:26pm UTC](https://discourse.julialang.org/t/iostream-buffering-pitfalls-when-communicating-to-a-device-file/130071 "2025-08-04T21:26:32Z")

</div>

I was talking to an ADS1115 ADC over I²C via /dev/i2c-1 on a Raspberry Pi 4. My first attempt was using high-level IOStream APIs like write(io, bytes) and read(io, n), and it worked but only for the first value. Every v…

---

## [Help with reinterperating result of ccall](https://discourse.julialang.org/t/help-with-reinterperating-result-of-ccall/131227)

<div class="topic-metadata">

**Author:** [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Replies:** 8\
**Last updated:** [July 31, 2025, 1:28pm UTC](https://discourse.julialang.org/t/help-with-reinterperating-result-of-ccall/131227 "2025-07-31T13:28:32Z")

</div>

So I have a function in a C library that returns a uint16\_t and I call it something like this (@ccall ".\\\\lib.dll".crc16()::UInt16) However, this gives the wrong result. But (@ccall ".\\\\lib.dll".crc16()::UInt16) |\> x…

---

## [Avoid copy when using data for Ptr{T}](https://discourse.julialang.org/t/avoid-copy-when-using-data-for-ptr-t/128602)

<div class="topic-metadata">

**Author:** [@aitzkora](https://discourse.julialang.org/u/aitzkora)\
**Replies:** 4\
**Last updated:** [May 2, 2025, 7:26pm UTC](https://discourse.julialang.org/t/avoid-copy-when-using-data-for-ptr-t/128602 "2025-05-02T19:26:25Z")

</div>

Hi, I call a fortran code which calls Julia trough a @cfunction using pointers (Ptr{T}), and I want to avoid copying data from Fortran in Julia such as in the following code using Libdl:dlopen, dlsym using Test funct…

---

## [Leveraging the GDAL VSI for “raw” access to NetCDF/HDF5 files inside a Zip archive?](https://discourse.julialang.org/t/leveraging-the-gdal-vsi-for-raw-access-to-netcdf-hdf5-files-inside-a-zip-archive/128129)

<div class="topic-metadata">

**Author:** [@Oblomov](https://discourse.julialang.org/u/Oblomov)\
**Replies:** 9\
**Last updated:** [April 17, 2025, 6:27am UTC](https://discourse.julialang.org/t/leveraging-the-gdal-vsi-for-raw-access-to-netcdf-hdf5-files-inside-a-zip-archive/128129 "2025-04-17T06:27:47Z")

</div>

Hello all, I have an interesting conundrum. My situation is the following: I have some data which is distributed as a zip archive of .nc files. The files are rather large, so I would prefer to not unzip the archive to r…

---

## [GC error / sefgault in a simple C wrapper](https://discourse.julialang.org/t/gc-error-sefgault-in-a-simple-c-wrapper/127032)

<div class="topic-metadata">

**Author:** [@Krastanov](https://discourse.julialang.org/u/Krastanov)\
**Replies:** 5\
**Last updated:** [March 17, 2025, 1:27pm UTC](https://discourse.julialang.org/t/gc-error-sefgault-in-a-simple-c-wrapper/127032 "2025-03-17T13:27:39Z")

</div>

I am attempting to make a julia wrapper for a C library. The C library is already available as a jll. I was attempting to use Clang.jl to make the wrapper, but whatever I am doing seems to be causing segfaults on garbage…

---

## [Reading bytes from a pointer passed to C via ccall in Julia](https://discourse.julialang.org/t/reading-bytes-from-a-pointer-passed-to-c-via-ccall-in-julia/127014)

<div class="topic-metadata">

**Author:** [@Ochibobo](https://discourse.julialang.org/u/Ochibobo)\
**Replies:** 3\
**Last updated:** [March 16, 2025, 8:48pm UTC](https://discourse.julialang.org/t/reading-bytes-from-a-pointer-passed-to-c-via-ccall-in-julia/127014 "2025-03-16T20:48:02Z")

</div>

Hello… I have a C function that has a pointer as one of the parameters. The function structure looks as follows: int fn(..., void\*\* result){ // body... \*result = some\_bytes; // body... } In Julia, part of the ccall pa…

---

## [Calling C/Fortran program that embeds Julia in Julia](https://discourse.julialang.org/t/calling-c-fortran-program-that-embeds-julia-in-julia/126839)

<div class="topic-metadata">

**Author:** [@AreWeDreaming](https://discourse.julialang.org/u/AreWeDreaming)\
**Replies:** 2\
**Last updated:** [March 12, 2025, 10:52pm UTC](https://discourse.julialang.org/t/calling-c-fortran-program-that-embeds-julia-in-julia/126839 "2025-03-12T22:52:24Z")

</div>

We have a Julia framework that needs to interact with a lot of legacy Fortran/C(++) applications. Instead of manually preparing the proper interface for the applications which involves lots of manual type conversions, we…

---

## [C implementation of function being ~4 times faster even absence of allocs](https://discourse.julialang.org/t/c-implementation-of-function-being-4-times-faster-even-absence-of-allocs/126495)

<div class="topic-metadata">

**Author:** [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Replies:** 28\
**Last updated:** [March 5, 2025, 10:42pm UTC](https://discourse.julialang.org/t/c-implementation-of-function-being-4-times-faster-even-absence-of-allocs/126495 "2025-03-05T22:42:57Z")

</div>

Hi there, I am in need to optimize as much as possible the function I will present here. I moved it from C to Julia for convenience since the operations around it become much easier but I am getting significantly worst …

---

## [Debugging "could not load symbol ..." from \_jll package](https://discourse.julialang.org/t/debugging-could-not-load-symbol-from-jll-package/125340)

<div class="topic-metadata">

**Author:** [@suvayu](https://discourse.julialang.org/u/suvayu)\
**Replies:** 5\
**Last updated:** [January 29, 2025, 1:17pm UTC](https://discourse.julialang.org/t/debugging-could-not-load-symbol-from-jll-package/125340 "2025-01-29T13:17:14Z")

</div>

I’m trying to debug an upstream issue with one of my dependencies (DuckDB). To summarise briefly, for the latest release everything works as expected on Linux, but the windows package fails to load a symbol from DuckDB\_…

---

## [Create\_library method not exporting the ccallable function](https://discourse.julialang.org/t/create-library-method-not-exporting-the-ccallable-function/124950)

<div class="topic-metadata">

**Author:** [@Sandy45](https://discourse.julialang.org/u/Sandy45)\
**Replies:** 0\
**Last updated:** [January 20, 2025, 6:29am UTC](https://discourse.julialang.org/t/create-library-method-not-exporting-the-ccallable-function/124950 "2025-01-20T06:29:36Z")

</div>

I am trying to precompile my module using create\_library method and try to call the functions exported in dll files from my julia app but create\_library isn’t exporting ccallable functions that has been created in my mod…

---

## [Seeking clarification on Ptr vs Ref in ccall](https://discourse.julialang.org/t/seeking-clarification-on-ptr-vs-ref-in-ccall/96883)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 11\
**Last updated:** [January 16, 2025, 12:42am UTC](https://discourse.julialang.org/t/seeking-clarification-on-ptr-vs-ref-in-ccall/96883 "2025-01-16T00:42:39Z")

</div>

Suppose I have a C code int sum(int \*a, int n){ int s = 0; for(int i=0; i\<n; i++){ s += a\[i\]; } return s; } and I can call this from Julia as julia\> ccall((:sum, "./libsum.so"), Cint, (Ref{Cint},Cint), Cint\[1,2,…

---

## [\`ccall\` on Windows \`could not load symbol. The specified procedure could not be found\`](https://discourse.julialang.org/t/ccall-on-windows-could-not-load-symbol-the-specified-procedure-could-not-be-found/66291)

<div class="topic-metadata">

**Author:** [@nlaws](https://discourse.julialang.org/u/nlaws)\
**Replies:** 18\
**Last updated:** [January 3, 2025, 9:59am UTC](https://discourse.julialang.org/t/ccall-on-windows-could-not-load-symbol-the-specified-procedure-could-not-be-found/66291 "2025-01-03T09:59:59Z")

</div>

I am loading in a custom C library and then calling functions with @ccall. Everything works fine on Apple and Linux with: hdl = Libc.Libdl.dlopen("path/to/clibrary", Libc.Libdl.RTLD\_GLOBAL) wind\_module = @ccall ssc\_modu…

---

## [Segmentation fault when using ccall to call a BLAS-like extension function from Intel MKL](https://discourse.julialang.org/t/segmentation-fault-when-using-ccall-to-call-a-blas-like-extension-function-from-intel-mkl/123377)

<div class="topic-metadata">

**Author:** [@NatSpring](https://discourse.julialang.org/u/NatSpring)\
**Replies:** 7\
**Last updated:** [December 3, 2024, 9:27am UTC](https://discourse.julialang.org/t/segmentation-fault-when-using-ccall-to-call-a-blas-like-extension-function-from-intel-mkl/123377 "2024-12-03T09:27:02Z")

</div>

I have written many Julia wrapper-functions that call routines from various parts of the Intel oneAPI library via the library’s .so file with ccall. This typically works without issue for BLAS routines, LAPACK routines a…

---

## [Example of registering a finalizer for unsafe\_wrapped data from ccall](https://discourse.julialang.org/t/example-of-registering-a-finalizer-for-unsafe-wrapped-data-from-ccall/122499)

<div class="topic-metadata">

**Author:** [@gmcardle](https://discourse.julialang.org/u/gmcardle)\
**Replies:** 9\
**Last updated:** [November 12, 2024, 2:49pm UTC](https://discourse.julialang.org/t/example-of-registering-a-finalizer-for-unsafe-wrapped-data-from-ccall/122499 "2024-11-12T14:49:55Z")

</div>

Hi, I’m using ccall on a C library that returns a pointer to some data that was malloced in the library and requires a separate API call to close the resource that the data came from. The dataset could be quite large (a …

---

## [How to use ccall, cconvert, and unsafe\_convert in a convenient and memory-safe way?](https://discourse.julialang.org/t/how-to-use-ccall-cconvert-and-unsafe-convert-in-a-convenient-and-memory-safe-way/41932)

<div class="topic-metadata">

**Author:** [@sloede](https://discourse.julialang.org/u/sloede)\
**Replies:** 18\
**Last updated:** [June 24, 2020, 11:50am UTC](https://discourse.julialang.org/t/how-to-use-ccall-cconvert-and-unsafe-convert-in-a-convenient-and-memory-safe-way/41932 "2020-06-24T11:50:08Z")

</div>

I am writing Julia code to conveniently interface a C library, which in turn is just an interface to a C++ library. Therefore, many times I have to store pointers to void as the C interface does not know anything about t…

---

## [Allocatable Multidimensional Arrays in Fortran](https://discourse.julialang.org/t/allocatable-multidimensional-arrays-in-fortran/119535)

<div class="topic-metadata">

**Author:** [@Jason\_Meziere](https://discourse.julialang.org/u/Jason_Meziere)\
**Replies:** 9\
**Last updated:** [September 20, 2024, 2:43pm UTC](https://discourse.julialang.org/t/allocatable-multidimensional-arrays-in-fortran/119535 "2024-09-20T14:43:06Z")

</div>

I am attempting to wrap a fortran package in Julia. In many of the functions, there are 2D arrays that are specified as ALLOCATABLE. Does Julia have a way to handle this? And what is the proper way to pass these values i…

---

## [Julia -\> C (Pthread) -\> Julia Saxpy with Threads](https://discourse.julialang.org/t/julia-c-pthread-julia-saxpy-with-threads/118097)

<div class="topic-metadata">

**Author:** [@miniskar](https://discourse.julialang.org/u/miniskar)\
**Replies:** 1\
**Last updated:** [August 12, 2024, 4:49pm UTC](https://discourse.julialang.org/t/julia-c-pthread-julia-saxpy-with-threads/118097 "2024-08-12T16:49:28Z")

</div>

I am having an C++ library environment where I am supposed to call Julia kernel (example SAXPY) with threading. A minimum work example to illustrate the issue is given below. The Julia main() function calls ‘call\_direc…

---

## [Create a custom @ccall](https://discourse.julialang.org/t/create-a-custom-ccall/117243)

<div class="topic-metadata">

**Author:** [@chkat](https://discourse.julialang.org/u/chkat)\
**Replies:** 4\
**Last updated:** [July 22, 2024, 12:20pm UTC](https://discourse.julialang.org/t/create-a-custom-ccall/117243 "2024-07-22T12:20:54Z")

</div>

I am trying to create a macro that replaces the @ccall in my code. My idea is to create something like this: macro my\_ccall(arg) custom\_function\_before\_ccall() @ccall arg end I am having trouble with the typ…

---

## [Passing a function over vectors as an argument to ccall](https://discourse.julialang.org/t/passing-a-function-over-vectors-as-an-argument-to-ccall/114487)

<div class="topic-metadata">

**Author:** [@brunompacheco](https://discourse.julialang.org/u/brunompacheco)\
**Replies:** 3\
**Last updated:** [May 21, 2024, 1:55pm UTC](https://discourse.julialang.org/t/passing-a-function-over-vectors-as-an-argument-to-ccall/114487 "2024-05-21T13:55:37Z")

</div>

I am not being able to properly pass a julia-defined function that takes vector and scalar values to C-defined functions. I have two functions in C EXPORT\_C double apply\_fun\_simple(double (\*fun)(double\*), double\* x) { …

---

## [Guidelines for wrapping a simple C library in Julia](https://discourse.julialang.org/t/guidelines-for-wrapping-a-simple-c-library-in-julia/112335)

<div class="topic-metadata">

**Author:** [@pjssilva](https://discourse.julialang.org/u/pjssilva)\
**Replies:** 6\
**Last updated:** [March 31, 2024, 11:57pm UTC](https://discourse.julialang.org/t/guidelines-for-wrapping-a-simple-c-library-in-julia/112335 "2024-03-31T23:57:53Z")

</div>

I am scratching my own itch here and decided to write a wrapper to a small C library I wrote to solve the problem of projecting a point onto the intersection of a box and a hyperplane. Is there a good “best practices” d…

---

## [Losing bytes when reinterpreting](https://discourse.julialang.org/t/losing-bytes-when-reinterpreting/111842)

<div class="topic-metadata">

**Author:** [@ion](https://discourse.julialang.org/u/ion)\
**Replies:** 7\
**Last updated:** [March 19, 2024, 11:09pm UTC](https://discourse.julialang.org/t/losing-bytes-when-reinterpreting/111842 "2024-03-19T23:09:55Z")

</div>

Hi all, I am trying to get data over to C, and I went with a ccall that takes in a buffer from julia. The issue I am having is, the data at teh end of my struct is getting chopped off. @kwdef struct CntlOutput time\_…

---

## [\[CCALL/INTEROP\] Get a \`Ptr\` for the last (or arbitrary) element of an array](https://discourse.julialang.org/t/ccall-interop-get-a-ptr-for-the-last-or-arbitrary-element-of-an-array/111360)

<div class="topic-metadata">

**Author:** [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Replies:** 2\
**Last updated:** [March 8, 2024, 3:19pm UTC](https://discourse.julialang.org/t/ccall-interop-get-a-ptr-for-the-last-or-arbitrary-element-of-an-array/111360 "2024-03-08T15:19:56Z")

</div>

Sorry, I tried to find it myself in documentation but was not able to find a good answer. I want to wrap a C function that takes two pointers, one for the first element of an array, the other for the last element of the…

---

## [Fastest \`sqrt\` and \`log\` with negative check](https://discourse.julialang.org/t/fastest-sqrt-and-log-with-negative-check/107575)

<div class="topic-metadata">

**Author:** [@DanDoe](https://discourse.julialang.org/u/DanDoe)\
**Replies:** 17\
**Last updated:** [January 14, 2024, 12:23pm UTC](https://discourse.julialang.org/t/fastest-sqrt-and-log-with-negative-check/107575 "2024-01-14T12:23:15Z")

</div>

NaNMath.jl implements special functions such as sqrt and log which return NaN if called with negative argument. The implementation of sqrt is given by sqrt(x::T) where {T\<:AbstractFloat} = x \< 0.0 ? T(NaN) : Base.sqrt(…

---

## [@ccall: returning a pointer to an array](https://discourse.julialang.org/t/ccall-returning-a-pointer-to-an-array/108329)

<div class="topic-metadata">

**Author:** [@rmfritz](https://discourse.julialang.org/u/rmfritz)\
**Replies:** 4\
**Last updated:** [January 5, 2024, 4:13am UTC](https://discourse.julialang.org/t/ccall-returning-a-pointer-to-an-array/108329 "2024-01-05T04:13:09Z")

</div>

I am trying to wrap a C function that returns a pointer to an array of UInt8, and I can’t quite figure out how to pass that pointer in. The C function signature is: int tmMapPicture(uby8 \*\*psp, int \*xp, int \*yp, … A p…

---

## [Line number info missing when Windows DLL gets EXCEPTION\_ACCESS\_VIOLATION](https://discourse.julialang.org/t/line-number-info-missing-when-windows-dll-gets-exception-access-violation/108353)

<div class="topic-metadata">

**Author:** [@Kirby\_Zhang](https://discourse.julialang.org/u/Kirby_Zhang)\
**Replies:** 2\
**Last updated:** [January 4, 2024, 6:32pm UTC](https://discourse.julialang.org/t/line-number-info-missing-when-windows-dll-gets-exception-access-violation/108353 "2024-01-04T18:32:53Z")

</div>

The DLL was compiled using MSVC toolchain with debug configuration. A .pdb file was generated alongside the .dll file. But it seems line number information is not being made available to Julia’s access violation handler: …

---

## [Passing struct by value in static compiling](https://discourse.julialang.org/t/passing-struct-by-value-in-static-compiling/107597)

<div class="topic-metadata">

**Author:** [@wujinq](https://discourse.julialang.org/u/wujinq)\
**Replies:** 2\
**Last updated:** [December 14, 2023, 5:28am UTC](https://discourse.julialang.org/t/passing-struct-by-value-in-static-compiling/107597 "2023-12-14T05:28:07Z")

</div>

We know in Julia structs are passed by reference, and this is also the case in StaticCompiler.jl: using StaticTools using StaticCompiler struct StudentInfo name::StaticString id::Cint end id(student::StudentI…

[Next page](https://discourse.julialang.org/tag/ccall/38.md?match_all_tags=true&page=1&tags%5B%5D=ccall)
