# HDF5 cannot compile in M1 pro mac

**URL:** <https://discourse.julialang.org/t/hdf5-cannot-compile-in-m1-pro-mac/71097>\
**Category:** General Usage\
**Tags:** package, hdf5, error, mac-m1\
**Created:** [November 7, 2021, 2:12pm UTC](https://discourse.julialang.org/t/hdf5-cannot-compile-in-m1-pro-mac/71097 "2021-11-07T14:12:57Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![wzy](https://avatars.discourse-cdn.com/v4/letter/w/e99b99/32.png) [@wzy](https://discourse.julialang.org/u/wzy)\
**Post date:** [November 7, 2021, 2:12pm UTC](https://discourse.julialang.org/t/hdf5-cannot-compile-in-m1-pro-mac/71097/1 "2021-11-07T14:12:57Z")

</div>

The julia version is v1.7.0 rc-2, installed by official dmg.  
OS: OSX Monterey

Hope to learn about how to resolve this problem, thanks!

The log:

julia\> using HDF5  
[Info: Precompiling HDF5 [f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f]  
ERROR: LoadError: UndefVarError: libhdf5 not defined  
Stacktrace:  
[1] top-level scope  
@ ~/.julia/packages/HDF5/pIJra/src/api\_types.jl:119  
[2] include(mod::Module, \_path::String)  
@ Base ./Base.jl:420  
[3] include(x::String)  
@ HDF5 ~/.julia/packages/HDF5/pIJra/src/HDF5.jl:1  
[4] top-level scope  
@ ~/.julia/packages/HDF5/pIJra/src/HDF5.jl:51  
[5] include  
@ ./Base.jl:420 [inlined]  
[6] include\_package\_for\_output(pkg::Base.PkgId, input::String, depot\_path::Vector{String}, dl\_load\_path::Vector{String}, load\_path::Vector{String}, concrete\_deps::Vector{Pair{Base.PkgId, UInt64}}, source::Nothing)  
@ Base ./loading.jl:1318  
[7] top-level scope  
@ none:1  
[8] eval  
@ ./boot.jl:373 [inlined]  
[9] eval(x::Expr)  
@ Base.MainInclude ./client.jl:453  
[10] top-level scope  
@ none:1  
in expression starting at /Users/John/.julia/packages/HDF5/pIJra/src/api\_types.jl:119  
in expression starting at /Users/John/.julia/packages/HDF5/pIJra/src/HDF5.jl:1  
ERROR: Failed to precompile HDF5 [f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f] to /Users/John/.julia/compiled/v1.7/HDF5/jl\_Ku0anm.  
Stacktrace:  
[1] error(s::String)  
@ Base ./error.jl:33  
[2] compilecache(pkg::Base.PkgId, path::String, internal\_stderr::IO, internal\_stdout::IO, ignore\_loaded\_modules::Bool)  
@ Base ./loading.jl:1466  
[3] compilecache(pkg::Base.PkgId, path::String)  
@ Base ./loading.jl:1410  
[4] \_require(pkg::Base.PkgId)  
@ Base ./loading.jl:1120  
[5] require(uuidkey::Base.PkgId)  
@ Base ./loading.jl:1013  
[6] require(into::Module, mod::Symbol)  
@ Base ./loading.jl:997

---

<div class="post-metadata">

**Author:** ![kylebeggs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kylebeggs/32/43348_2.png) [@kylebeggs](https://discourse.julialang.org/u/kylebeggs)\
**Post date:** [November 24, 2021, 7:25pm UTC](https://discourse.julialang.org/t/hdf5-cannot-compile-in-m1-pro-mac/71097/2 "2021-11-24T19:25:42Z")

</div>

I have the same issue. I even try directly giving the path to libhdf5 but it still doesn’t work.

Edit - Got it to work. I removed the .julia folder in your home directory completely, upgraded to 1.7.0 rc-3, and in my terminal exported the path to libhdf5 like this `export JULIA_HDF5_PATH=/opt/homebrew/Cellar/hdf5/1.12.1` which I installed with homebrew, obviously by the path. Then started Julia and ran these commands `using Pkg; Pkd.add("HDF5"); Pkg.build("HDF5")`.

---

<div class="post-metadata">

**Author:** ![wzy](https://avatars.discourse-cdn.com/v4/letter/w/e99b99/32.png) [@wzy](https://discourse.julialang.org/u/wzy)\
**Post date:** [December 11, 2021, 11:25pm UTC](https://discourse.julialang.org/t/hdf5-cannot-compile-in-m1-pro-mac/71097/3 "2021-12-11T23:25:40Z")

</div>

It also worked for me. Many thanks for the solution!

---

<div class="post-metadata">

**Author:** ![Xavier\_Gonzalez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xavier_gonzalez/32/36033_2.png) [@Xavier\_Gonzalez](https://discourse.julialang.org/u/Xavier_Gonzalez)\
**Post date:** [May 6, 2022, 5:09pm UTC](https://discourse.julialang.org/t/hdf5-cannot-compile-in-m1-pro-mac/71097/4 "2022-05-06T17:09:24Z")

</div>

Thank you so much for this solution. I’m trying to follow these steps. I have julia version 1.7.2, which is what I think is recommended for M1 chip.

I used homebrew to install hdf5 as you recommend, and added to the path.

I then ran `using Pkg; Pkg.add("HDF5")` without any problem.

However, when I ran `Pkg.build("HDF5")` I got the following error:

Error building `HDF5`:

[ Info: using system HDF5

ERROR: LoadError: libhdf5 could not be found

Do you know what might be going wrong?

---

<div class="post-metadata">

**Author:** ![kylebeggs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kylebeggs/32/43348_2.png) [@kylebeggs](https://discourse.julialang.org/u/kylebeggs)\
**Post date:** [May 6, 2022, 5:36pm UTC](https://discourse.julialang.org/t/hdf5-cannot-compile-in-m1-pro-mac/71097/5 "2022-05-06T17:36:08Z")

</div>

It looks like it’s not using the home brew hdf5. There is an environment variable within julia (not your OS) called JULIA\_LIBHDF5 or something similar that you need to set to point to the brew hdf5 install. I am mobile right now but respond if you can’t get it and I’ll be able to check exactly what my settings are later tonight.

---

<div class="post-metadata">

**Author:** ![Xavier\_Gonzalez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xavier_gonzalez/32/36033_2.png) [@Xavier\_Gonzalez](https://discourse.julialang.org/u/Xavier_Gonzalez)\
**Post date:** [May 9, 2022, 8:19pm UTC](https://discourse.julialang.org/t/hdf5-cannot-compile-in-m1-pro-mac/71097/6 "2022-05-09T20:19:13Z")

</div>

> [@kylebeggs](#):
>
> export JULIA\_HDF5\_PATH=/opt/homebrew/Cellar/hdf5/1.12.1

Thank you so much! I really appreciate your saying this. yes, if you could check your settings I would be super grateful. I am trying to follow this website, which talks about environment variables in Julia.

[Environment Variables · The Julia Language](https://docs.julialang.org/en/v1/manual/environment-variables/#:~:text=The%20environment%20variables%20that%20Julia,include%20JULIA%20in%20their%20names).

It talks about editing the file ~/.julia/config/startup.jl

But when I go into my .julia folder, my only options are artifacts, conda, logs, pluto\_notebooks, registries, compiled, environments, packages, prefs, and scratchspaces

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [May 9, 2022, 8:41pm UTC](https://discourse.julialang.org/t/hdf5-cannot-compile-in-m1-pro-mac/71097/7 "2022-05-09T20:41:41Z")

</div>

startup.jl is optional. If it isn’t there, create one.

---

<div class="post-metadata">

**Author:** ![Xavier\_Gonzalez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xavier_gonzalez/32/36033_2.png) [@Xavier\_Gonzalez](https://discourse.julialang.org/u/Xavier_Gonzalez)\
**Post date:** [May 9, 2022, 9:53pm UTC](https://discourse.julialang.org/t/hdf5-cannot-compile-in-m1-pro-mac/71097/8 "2022-05-09T21:53:08Z")

</div>

right, but there is also not even a config folder in my settings

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 9, 2022, 9:54pm UTC](https://discourse.julialang.org/t/hdf5-cannot-compile-in-m1-pro-mac/71097/9 "2022-05-09T21:54:30Z")

</div>

@giordano Shouldn’t there be another way of doing this with HDF5\_jll.jl and a Preferences.jl override?

I’m also confused because I thought we have

> <https://github.com/JuliaBinaryWrappers/HDF5_jll.jl/blob/main/src/wrappers/aarch64-apple-darwin.jl>

---

<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 9, 2022, 10:01pm UTC](https://discourse.julialang.org/t/hdf5-cannot-compile-in-m1-pro-mac/71097/10 "2022-05-09T22:01:49Z")

</div>

Depends on the version of `HDF5_jll.jl` they’re using. May not be the last one. You can see it with

```julia
]status -m HDF5_jll

```

---

<div class="post-metadata">

**Author:** ![kylebeggs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kylebeggs/32/43348_2.png) [@kylebeggs](https://discourse.julialang.org/u/kylebeggs)\
**Post date:** [May 10, 2022, 12:01pm UTC](https://discourse.julialang.org/t/hdf5-cannot-compile-in-m1-pro-mac/71097/11 "2022-05-10T12:01:59Z")

</div>

@mkitti you still need to point Julia to the brew install of hdf5. @Xavier_Gonzalez Just put in your .zshrc or .bashrc or whatever shell you use `export JULIA_HDF5_PATH=/opt/homebrew/Cellar/hdf5/1.12.1_1 ` make sure to match the version number at the end. you can check your version number by just doing `ls -l /opt/homebrew/Cellar/hdf5/`. also start a new shell and then a new Julia instance when you go to test. then do add HDF5, build HDF5 etc

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 10, 2022, 1:54pm UTC](https://discourse.julialang.org/t/hdf5-cannot-compile-in-m1-pro-mac/71097/12 "2022-05-10T13:54:53Z")

</div>

@kylebeggs I’m uncertain why homebrew is still needed. It could certainly still be useful, but I’m not sure why it is _necessary_ as of January 10th, 2022.

As I posted above, HDF5\_jll now appears to provide support aarch64-apple-darwin and giordano is not objecting to that assertion.

![image](https://global.discourse-cdn.com/julialang/original/3X/2/3/23df7a6a27c4c40dadfa0411fc9b8981caaf8a4f.png)

---

<div class="post-metadata">

**Author:** ![kylebeggs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kylebeggs/32/43348_2.png) [@kylebeggs](https://discourse.julialang.org/u/kylebeggs)\
**Post date:** [May 10, 2022, 3:38pm UTC](https://discourse.julialang.org/t/hdf5-cannot-compile-in-m1-pro-mac/71097/13 "2022-05-10T15:38:46Z")

</div>

Oh I see, yes it’s possible it’s not needed anymore. I was just saying what worked for me (which was before Jan 2022)
