# "Cfunction: closures are not supported on this platform" error for barplot?

**URL:** https://discourse.julialang.org/t/cfunction-closures-are-not-supported-on-this-platform-error-for-barplot/98281
**Category:** New to Julia
**Created:** [May 3, 2023, 9:14pm UTC](https://discourse.julialang.org/t/cfunction-closures-are-not-supported-on-this-platform-error-for-barplot/98281 "2023-05-03T21:14:39Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![julia2kx](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@julia2kx](https://discourse.julialang.org/u/julia2kx)
#### Post date: [May 3, 2023, 9:14pm UTC](https://discourse.julialang.org/t/cfunction-closures-are-not-supported-on-this-platform-error-for-barplot/98281/1 "2023-05-03T21:14:40Z")

</div>

Got the error “cfunction: closures are not supported on this platform”

fig2 = Figure((6, 4), “in”)  
2 xs = [“1”, “2”, “3”, “4”, “5”, “6”, “7”]  
3 barplot(xs, drdp[end, :], dpi=300)  
4 ylim((0, 1))  
5 ylabel(“Degree of Rate Control”)  
6 xlabel(“Step id”)  
7 savefig(“si-3.png”)

Stacktrace:  
[1] axeslbl(x\_tick::Float64, y\_tick::Float64, x\_org::Float64, y\_org::Float64, major\_x::Int64, major\_y::Int64, tick\_size::Float64, fx::Function, fy::GRUtils.var"#43#44"{typeof(identity)})  
@ GR ~/.julia/packages/GR/M9Dkl/src/GR.jl:2285  
[2] draw(ax::GRUtils.Axes, background::Bool)  
@ GRUtils ~/.julia/packages/GRUtils/pFWly/src/axes.jl:510  
[3] draw  
@ ~/.julia/packages/GRUtils/pFWly/src/axes.jl:449 [inlined]  
[4] draw(p::GRUtils.PlotObject)  
@ GRUtils ~/.julia/packages/GRUtils/pFWly/src/plotobjects.jl:213  
[5] draw(f::Figure)  
@ GRUtils ~/.julia/packages/GRUtils/pFWly/src/figures.jl:200  
[6] savefig  
@ ~/.julia/packages/GRUtils/pFWly/src/frontend.jl:1470 [inlined]  
[7] savefig(filename::String)  
@ GRUtils ~/.julia/packages/GRUtils/pFWly/src/frontend.jl:1469  
[8] top-level scope  
@ In[16]:7

–

Full code:  
using GRUtils  
using DifferentialEquations  
using DiffEqSensitivity, ForwardDiff  
using LaTeXStrings

kf0 = Array([1.33e8, 2.01e11, 2.64e6, 5.24e1, 2.05e5, 1.48e12, 5.32e2])  
K = Array([2.15e2, 5.93e-5, 6.28e-2, 1.18e-5, 1.03e3, 1.92e5, 4.50e1])

function calc\_rate2(y, kf)  
global K  
kr = kf ./ K  
press = Array([0.07, 0.21, 0.085, 0.38])  
press = press .\* 1.01325  
fwd\_factor = Array([press[1] \* y[1], press[2] \* y[1], y[3] \* y[1], y[5] \*  
y[1], y[2] \* y[6], y[7], y[4]^2])  
rev\_factor = Array([y[2], y[3], y[4] \* y[5], y[4] \* y[6], y[7] \* y[1],  
press[3] \* y[1], press[4] \* y[1]^2])  
r = kf .\* fwd\_factor .- kr .\* rev\_factor  
return r  
end

function calc\_overall\_rate2(y, kf)  
global K  
kr = kf ./ K  
press = Array([0.07, 0.21, 0.085, 0.38])  
press = press .\* 1.01325  
r1 = kf[7] \* y[4]^2 - kr[7] \* press[4] \* y[1]^2  
return r1  
end

function state\_eqn2(y, kf, t)  
r = calc\_rate2(y, kf)  
eq1 = -r[1] - r[2] -r[3] -r[4] + r[5] + r[6] + 2 \* r[7] # \*  
eq2 = r[1] - r[5] # CO\*  
eq3 = r[2] - r[3] # H2O\*  
eq4 = r[3] + r[4] - 2 \* r[7] # H\*  
eq5 = r[3] - r[4] # OH\*  
eq6 = r[4] - r[5] # O\*  
eq7 = r[5] - r[6] # CO2\*  
Array([eq1, eq2, eq3, eq4, eq5, eq6, eq7])  
end

tspan = (0., 50.)  
y0 = [0.9; 0.01; 0.01; 0.01; 0.01; 0.01; 0.05]  
prob2 = ODEProblem(state\_eqn2, y0, tspan, kf0)

function rate\_wrapper2(p)  
p = exp.(p)  
nt = 501  
\_prob = remake(prob2, p=p)  
theta\_sol = Array(solve(\_prob, Kvaerno5(), saveat=LinRange(2.0, 50.0, nt), sensealg=ForwardDiffSensitivity(), atol=1e-8, rtol=1e-8))’ # [nt, nu]  
p\_matrix = reshape(p, 1, size(p, 1)) # [1, np]  
p\_repeat = repeat(p\_matrix, nt, 1) # [nt, np]  
r = Array{Real, 1}(undef, nt)  
for i in 1:nt  
r[i] = calc\_overall\_rate2(theta\_sol[i, :], p\_repeat[i, :])  
end  
return log.(r)  
end

drdp = ForwardDiff.jacobian(rate\_wrapper2, log.(kf0))

fig2 = Figure((6, 4), “in”)  
xs = [“1”, “2”, “3”, “4”, “5”, “6”, “7”]  
barplot(xs, drdp[end, :], dpi=300)  
ylim((0, 1))  
ylabel(“Degree of Rate Control”)  
xlabel(“Step id”)  
savefig(“si-3.png”)

also got a warning “Unrecognized keyword arguments: [:atol, :rtol]”

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [May 4, 2023, 1:03am UTC](https://discourse.julialang.org/t/cfunction-closures-are-not-supported-on-this-platform-error-for-barplot/98281/2 "2023-05-04T01:03:12Z")

</div>

What’s the platform? Ie what’s the output of `versioninfo()`?

---

<div class="post-metadata">

### Author: ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)
#### Post date: [May 4, 2023, 2:12am UTC](https://discourse.julialang.org/t/cfunction-closures-are-not-supported-on-this-platform-error-for-barplot/98281/3 "2023-05-04T02:12:01Z")

</div>

> [@StefanKarpinski](#):
>
> What’s the platform?

Probably ARM. Cfunction closures aren’t supported there.

---

<div class="post-metadata">

### Author: ![julia2kx](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@julia2kx](https://discourse.julialang.org/u/julia2kx)
#### Post date: [May 4, 2023, 5:35am UTC](https://discourse.julialang.org/t/cfunction-closures-are-not-supported-on-this-platform-error-for-barplot/98281/4 "2023-05-04T05:35:14Z")

</div>

Mac OS, MacBook Pro M1 (2021)

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [May 4, 2023, 6:07pm UTC](https://discourse.julialang.org/t/cfunction-closures-are-not-supported-on-this-platform-error-for-barplot/98281/5 "2023-05-04T18:07:21Z")

</div>

And what version of Julia? How did you install it? Output of versioninfo please…

---

<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 4, 2023, 11:16pm UTC](https://discourse.julialang.org/t/cfunction-closures-are-not-supported-on-this-platform-error-for-barplot/98281/6 "2023-05-04T23:16:07Z")

</div>

That’s a problem in the GR.jl package in the sense it should avoid using cfunction closures if possible at all, Julia just doesn’t support them on the ARM architecture because of a limitation of llvm, see the Note in [Calling C and Fortran Code · The Julia Language](https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/index.html#Closure-cfunctions) (the reference to powerpc is outdated as they now work on that architecture)
