# \#c

**URL:** https://discourse.julialang.org/tag/c/610.md

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

---

## [Designing a C ABI layer for a multi-lingual project](https://discourse.julialang.org/t/designing-a-c-abi-layer-for-a-multi-lingual-project/137150)

<div class="topic-metadata">

**Author:** [@BananaMaster3](https://discourse.julialang.org/u/BananaMaster3)\
**Replies:** 3\
**Last updated:** [May 20, 2026, 3:16am UTC](https://discourse.julialang.org/t/designing-a-c-abi-layer-for-a-multi-lingual-project/137150 "2026-05-20T03:16:15Z")

</div>

Hello all, I’m interested in creating a multi-lingual project with a Julia backend. I’d like to do this through a C ABI layer and would like advice on how to structure it. Since my usecase is a bit difficult to explain…

---

## [C calling convention mismatch?](https://discourse.julialang.org/t/c-calling-convention-mismatch/136624)

<div class="topic-metadata">

**Author:** [@danielmatz](https://discourse.julialang.org/u/danielmatz)\
**Replies:** 12\
**Last updated:** [May 13, 2026, 11:48am UTC](https://discourse.julialang.org/t/c-calling-convention-mismatch/136624 "2026-05-13T11:48:35Z")

</div>

I’m using PackageCompiler.jl to build a shared library, which I then link into a C driver program. One of my @ccallable functions takes a “large” (168 bytes) struct as an argument by value. Things worked fine on macOS, b…

---

## [Does \`String(unsafe\_wrap(cstring, len, own=true))\` free the memory it points to?](https://discourse.julialang.org/t/does-string-unsafe-wrap-cstring-len-own-true-free-the-memory-it-points-to/136315)

<div class="topic-metadata">

**Author:** [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Replies:** 2\
**Last updated:** [March 21, 2026, 1:47am UTC](https://discourse.julialang.org/t/does-string-unsafe-wrap-cstring-len-own-true-free-the-memory-it-points-to/136315 "2026-03-21T01:47:02Z")

</div>

If I have a Cstring from a @ccall that I am responsible for freeing, does converting that Cstring to a Julia String via s = String(unsafe\_wrap(Vector{UInt8}, Ptr{UInt8}(cstring), len, own=true)) automatically free the as…

---

## [Best practice for calling Julia functions via API](https://discourse.julialang.org/t/best-practice-for-calling-julia-functions-via-api/135086)

<div class="topic-metadata">

**Author:** [@Chrysoberyl](https://discourse.julialang.org/u/Chrysoberyl)\
**Replies:** 0\
**Last updated:** [January 15, 2026, 8:04pm UTC](https://discourse.julialang.org/t/best-practice-for-calling-julia-functions-via-api/135086 "2026-01-15T20:04:30Z")

</div>

In my setup, a Julia function calls a C/Rust function play(agent, environment), which spawns some threads, and call functions on agent. agent and environment are Julia objects. Each of these foreign threads gets registe…

---

## [Implement C-like command line arguments in Julia](https://discourse.julialang.org/t/implement-c-like-command-line-arguments-in-julia/67816)

<div class="topic-metadata">

**Author:** [@vinicius\_de\_lima](https://discourse.julialang.org/u/vinicius_de_lima)\
**Replies:** 8\
**Last updated:** [November 17, 2025, 1:07pm UTC](https://discourse.julialang.org/t/implement-c-like-command-line-arguments-in-julia/67816 "2025-11-17T13:07:15Z")

</div>

There is a way to reproduce C command line arguments behavior in Julia? int main(int argc, char \*\*argv) { /\* ... \*/ }

---

## [C program embedding Julia - works in terminal but breaks in pipes](https://discourse.julialang.org/t/c-program-embedding-julia-works-in-terminal-but-breaks-in-pipes/86973)

<div class="topic-metadata">

**Author:** [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Replies:** 8\
**Last updated:** [October 30, 2025, 2:43pm UTC](https://discourse.julialang.org/t/c-program-embedding-julia-works-in-terminal-but-breaks-in-pipes/86973 "2025-10-30T14:43:19Z")

</div>

I’d like to write a C program which embeds Julia code, and call this C program from an unrelated program using two-way pipes. While the C program works fine in the terminal, it breaks when called from pipes. Here’s a min…

---

## [Using legacy C code with autodifferentiation](https://discourse.julialang.org/t/using-legacy-c-code-with-autodifferentiation/132548)

<div class="topic-metadata">

**Author:** [@marcobonici](https://discourse.julialang.org/u/marcobonici)\
**Replies:** 4\
**Last updated:** [October 28, 2025, 4:31pm UTC](https://discourse.julialang.org/t/using-legacy-c-code-with-autodifferentiation/132548 "2025-10-28T16:31:56Z")

</div>

Hello, I am asking for some general guidance on the following task, There is a legacy code, written in C, that I would like to use directly in Julia. Ideally, I would like to be able to differentiate it as well (the co…

---

## [Embedding Julia in Windows](https://discourse.julialang.org/t/embedding-julia-in-windows/76693)

<div class="topic-metadata">

**Author:** [@DanielP](https://discourse.julialang.org/u/DanielP)\
**Replies:** 1\
**Last updated:** [July 12, 2025, 7:06pm UTC](https://discourse.julialang.org/t/embedding-julia-in-windows/76693 "2025-07-12T19:06:21Z")

</div>

Hi, I have tried to call my tested Julia function from C program on Windows 10. I am using gcc compiler (minGW). When I compile, link and launch my program from the IDE (I am using Code::Blocks IDE) it works fine. The co…

---

## [Calling C Code with Automatic Differentiation in Julia](https://discourse.julialang.org/t/calling-c-code-with-automatic-differentiation-in-julia/129503)

<div class="topic-metadata">

**Author:** [@fgittins](https://discourse.julialang.org/u/fgittins)\
**Replies:** 6\
**Last updated:** [June 2, 2025, 7:39am UTC](https://discourse.julialang.org/t/calling-c-code-with-automatic-differentiation-in-julia/129503 "2025-06-02T07:39:48Z")

</div>

Hi all, I’m reaching out to see if anyone in the Julia community has experience or advice on calling C code from Julia in a way that still supports automatic differentiation (AD). My motivation I’m working on a project…

---

## [How to build a wrapper around a C-style array using Julia C API?](https://discourse.julialang.org/t/how-to-build-a-wrapper-around-a-c-style-array-using-julia-c-api/129469)

<div class="topic-metadata">

**Author:** [@dmitry-kabanov](https://discourse.julialang.org/u/dmitry-kabanov)\
**Replies:** 4\
**Last updated:** [May 31, 2025, 12:55am UTC](https://discourse.julialang.org/t/how-to-build-a-wrapper-around-a-c-style-array-using-julia-c-api/129469 "2025-05-31T00:55:11Z")

</div>

Hi, I need to use the Julia C API to build a wrapper around a C-style array to use this array in Julia (the array is actually a Python NumPy array). The thing is that the array is a matrix (2D) and Julia uses Fortran-sty…

---

## [Julia vs C++ for computational mechanics - Implicit Material Point Method](https://discourse.julialang.org/t/julia-vs-c-for-computational-mechanics-implicit-material-point-method/129180)

<div class="topic-metadata">

**Author:** [@jowsky](https://discourse.julialang.org/u/jowsky)\
**Replies:** 13\
**Last updated:** [May 24, 2025, 5:20am UTC](https://discourse.julialang.org/t/julia-vs-c-for-computational-mechanics-implicit-material-point-method/129180 "2025-05-24T05:20:30Z")

</div>

TL;DR : Writing an implicit Material Point Method solver. Would it be that much slower in Julia than C++ for a similar time-effort ? Hello, I am PhD student working on simulating creeping snow. I am currently planning …

---

## [Something weird is going on with \`DenseArray\`](https://discourse.julialang.org/t/something-weird-is-going-on-with-densearray/129156)

<div class="topic-metadata">

**Author:** [@akriegman](https://discourse.julialang.org/u/akriegman)\
**Replies:** 3\
**Last updated:** [May 19, 2025, 11:24pm UTC](https://discourse.julialang.org/t/something-weird-is-going-on-with-densearray/129156 "2025-05-19T23:24:22Z")

</div>

From base/boot.jl: # commented-out definitions are implemented in C ... #abstract type AbstractArray{T,N} end #abstract type DenseArray{T,N} \<: AbstractArray{T,N} end ... #mutable struct Array{T,N} \<: DenseArray{T,N…

---

## [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…

---

## [Go is everything I wanted C to be](https://discourse.julialang.org/t/go-is-everything-i-wanted-c-to-be/126505)

<div class="topic-metadata">

**Author:** [@NonDairyNeutrino](https://discourse.julialang.org/u/NonDairyNeutrino)\
**Replies:** 1\
**Last updated:** [March 10, 2025, 3:50am UTC](https://discourse.julialang.org/t/go-is-everything-i-wanted-c-to-be/126505 "2025-03-10T03:50:18Z")

</div>

I’ve used C a little and mostly for scientific computing, but I’ve recently learned about some of the details of the Go programming language. It just…is everything I didn’t know I wanted from C (especially for strings).…

---

## [Using PackageCompiler Header file time modified even content not changed using force](https://discourse.julialang.org/t/using-packagecompiler-header-file-time-modified-even-content-not-changed-using-force/124441)

<div class="topic-metadata">

**Author:** [@xgdgsc](https://discourse.julialang.org/u/xgdgsc)\
**Replies:** 1\
**Last updated:** [January 5, 2025, 2:00pm UTC](https://discourse.julialang.org/t/using-packagecompiler-header-file-time-modified-even-content-not-changed-using-force/124441 "2025-01-05T14:00:00Z")

</div>

Currently the build command create\_library(".", "MyLib"; lib\_name="libmine", precompile\_execution\_file="build/generate\_precompile.jl", precompile\_statements\_file="build/additional\_precompile.jl", header\_…

---

## [Call libcuda cuLaunchKernel from Julia](https://discourse.julialang.org/t/call-libcuda-culaunchkernel-from-julia/124314)

<div class="topic-metadata">

**Author:** [@miniskar](https://discourse.julialang.org/u/miniskar)\
**Replies:** 2\
**Last updated:** [January 5, 2025, 8:30am UTC](https://discourse.julialang.org/t/call-libcuda-culaunchkernel-from-julia/124314 "2025-01-05T08:30:55Z")

</div>

I am trying to analyze the overheads of launching a CUDA task from Julia and also from C++. I see some gaps in Julia after successive launch of CUDA “saxpy\_cuda” kernel to non-blocking streams. I am wondering if it is be…

---

## [\`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…

---

## [Generate a function via macro and pass to @cfunction. Possible?](https://discourse.julialang.org/t/generate-a-function-via-macro-and-pass-to-cfunction-possible/123988)

<div class="topic-metadata">

**Author:** [@tqml](https://discourse.julialang.org/u/tqml)\
**Replies:** 7\
**Last updated:** [December 20, 2024, 11:59pm UTC](https://discourse.julialang.org/t/generate-a-function-via-macro-and-pass-to-cfunction-possible/123988 "2024-12-20T23:59:09Z")

</div>

I’m trying to write a macro that takes a function, creates a wrapper for it, passes the wrapper to @cfunction and finally passes the function pointer to an external C library. To further clarify the use-case here: I wan…

---

## [Dereferencing Ptr{Ptr{Int32}}](https://discourse.julialang.org/t/dereferencing-ptr-ptr-int32/123709)

<div class="topic-metadata">

**Author:** [@NimaPoshtiban](https://discourse.julialang.org/u/NimaPoshtiban)\
**Replies:** 21\
**Last updated:** [December 13, 2024, 1:34pm UTC](https://discourse.julialang.org/t/dereferencing-ptr-ptr-int32/123709 "2024-12-13T13:34:58Z")

</div>

Hi I’m using the Julia C interface to call a function from my dll Everything works fine Until I try to dereference it first\_row = unsafe\_load(result\_ptr) firsr\_num = unsafe\_load(first\_row) #= The matrix form is so…

---

## [Memory Arena](https://discourse.julialang.org/t/memory-arena/123764)

<div class="topic-metadata">

**Author:** [@NimaPoshtiban](https://discourse.julialang.org/u/NimaPoshtiban)\
**Replies:** 1\
**Last updated:** [December 12, 2024, 4:57pm UTC](https://discourse.julialang.org/t/memory-arena/123764 "2024-12-12T16:57:30Z")

</div>

Hello, dear members of the Julia Community. I want to manage heap space for external objects (e.g. C objects) by using an Arena How is it done in Julia? The simple definition of an Arena is “An arena is just a large,…

---

## [Unsafe\_wrap perform memory allocations](https://discourse.julialang.org/t/unsafe-wrap-perform-memory-allocations/123662)

<div class="topic-metadata">

**Author:** [@Sergey](https://discourse.julialang.org/u/Sergey)\
**Replies:** 6\
**Last updated:** [December 10, 2024, 3:48pm UTC](https://discourse.julialang.org/t/unsafe-wrap-perform-memory-allocations/123662 "2024-12-10T15:48:15Z")

</div>

Hi! Im trying to wrap c pointer array into julia as follows: function WrapArray(arr :: Ptr{Cdouble}, length :: Cint) :: Cdouble @timev wrapped = unsafe\_wrap(Vector{Cdouble}, arr, length) 0.000003 seconds (2 a…

---

## [Embedded julia catch exception](https://discourse.julialang.org/t/embedded-julia-catch-exception/123287)

<div class="topic-metadata">

**Author:** [@Sergey](https://discourse.julialang.org/u/Sergey)\
**Replies:** 1\
**Last updated:** [December 3, 2024, 12:10pm UTC](https://discourse.julialang.org/t/embedded-julia-catch-exception/123287 "2024-12-03T12:10:16Z")

</div>

Hi. Im trying to use julia as user function extension. So i embed it into my qt application. But if there is an error in julia code everything will crash. Is it possible to catch julia exceptions from c++ or i could …

---

## [How to create a Cstring from a String?](https://discourse.julialang.org/t/how-to-create-a-cstring-from-a-string/98566)

<div class="topic-metadata">

**Author:** [@heyx3](https://discourse.julialang.org/u/heyx3)\
**Replies:** 4\
**Last updated:** [May 9, 2023, 6:57pm UTC](https://discourse.julialang.org/t/how-to-create-a-cstring-from-a-string/98566 "2023-05-09T18:57:59Z")

</div>

I’m trying to implement callback functions for a C library, to get and set the clipboard text. My functions look like this: clipboard\_get(::Ptr{Cvoid})::Cstring = string(clipboard()) const CLIPBOARD\_FN\_GET = @cfunction(…

---

## [How to use Base.Libc.errno](https://discourse.julialang.org/t/how-to-use-base-libc-errno/118832)

<div class="topic-metadata">

**Author:** [@nhz2](https://discourse.julialang.org/u/nhz2)\
**Replies:** 3\
**Last updated:** [September 1, 2024, 7:20am UTC](https://discourse.julialang.org/t/how-to-use-base-libc-errno/118832 "2024-09-01T07:20:21Z")

</div>

The docs for errno in Julia states: The value of errno is only valid immediately after a ccall to a C library routine that sets it. Specifically, you cannot call errno at the next prompt in a REPL, because lots of code…

---

## [\[ANN\] CClosure.jl: C closures like what C does](https://discourse.julialang.org/t/ann-cclosure-jl-c-closures-like-what-c-does/81234)

<div class="topic-metadata">

**Author:** [@melonedo](https://discourse.julialang.org/u/melonedo)\
**Replies:** 0\
**Last updated:** [May 18, 2022, 6:16am UTC](https://discourse.julialang.org/t/ann-cclosure-jl-c-closures-like-what-c-does/81234 "2022-05-18T06:16:11Z")

</div>

Julia has a very powerful @cfunction macro that can make any pure Julia function callable to C. However, it only produces a single function pointer, contrary to modern C libraries where a pair of function pointer and a p…

---

## [C struct garbage collection not run frequently enough](https://discourse.julialang.org/t/c-struct-garbage-collection-not-run-frequently-enough/116919)

<div class="topic-metadata">

**Author:** [@mattsignorelli](https://discourse.julialang.org/u/mattsignorelli)\
**Replies:** 28\
**Last updated:** [July 14, 2024, 11:42pm UTC](https://discourse.julialang.org/t/c-struct-garbage-collection-not-run-frequently-enough/116919 "2024-07-14T23:42:04Z")

</div>

I have a Julia interface to a C library where each C struct represents a number. In Julia, the mutable struct just contains a Ptr to the C struct, and the finalizer calls the C destructor. These C structs can be very me…

---

## [Define a C++ struct/class in Julia for interop?](https://discourse.julialang.org/t/define-a-c-struct-class-in-julia-for-interop/112766)

<div class="topic-metadata">

**Author:** [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Replies:** 11\
**Last updated:** [April 19, 2024, 1:07pm UTC](https://discourse.julialang.org/t/define-a-c-struct-class-in-julia-for-interop/112766 "2024-04-19T13:07:22Z")

</div>

To efficiently call C or C++ libraries without an additional overhead of dereferencing pointers, you need to define a Julia struct with the same memory layout as the the struct/class in C or C++. For C, Clang.jl and CBin…

---

## [Example of Clang.jl wrapping C interface using GMP mpq\_t (also arrays of mpq\_t)](https://discourse.julialang.org/t/example-of-clang-jl-wrapping-c-interface-using-gmp-mpq-t-also-arrays-of-mpq-t/112864)

<div class="topic-metadata">

**Author:** [@JonT](https://discourse.julialang.org/u/JonT)\
**Replies:** 0\
**Last updated:** [April 12, 2024, 9:12am UTC](https://discourse.julialang.org/t/example-of-clang-jl-wrapping-c-interface-using-gmp-mpq-t-also-arrays-of-mpq-t/112864 "2024-04-12T09:12:22Z")

</div>

I’m stumbling through wrapping an interface to a C library using Clang.jl. Im hoping someone can. give me some hints about the best way to wrap methods passing and returning GMP mpq\_t types, or arrays of them. I found …

---

## [Two ways to get C++ interface class from C API](https://discourse.julialang.org/t/two-ways-to-get-c-interface-class-from-c-api/112522)

<div class="topic-metadata">

**Author:** [@sairus7](https://discourse.julialang.org/u/sairus7)\
**Replies:** 0\
**Last updated:** [April 4, 2024, 1:41pm UTC](https://discourse.julialang.org/t/two-ways-to-get-c-interface-class-from-c-api/112522 "2024-04-04T13:41:09Z")

</div>

Consider simple C++ interface class: ▶ File \`shape.h\` Since Cxx.jl in obsolete, so you cannot generate julia types from C++, and CxxWrap.jl means you have to make changes on C++ side, so I’ve made two C library wrappers …

---

## [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…

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