# XGBoost 'libxgboost' not defined error

**URL:** <https://discourse.julialang.org/t/xgboost-libxgboost-not-defined-error/100542>\
**Category:** New to Julia\
**Tags:** package\
**Created:** [June 19, 2023, 5:14am UTC](https://discourse.julialang.org/t/xgboost-libxgboost-not-defined-error/100542 "2023-06-19T05:14:28Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![frankd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frankd/32/50872_2.png) [@frankd](https://discourse.julialang.org/u/frankd)\
**Post date:** [June 19, 2023, 5:14am UTC](https://discourse.julialang.org/t/xgboost-libxgboost-not-defined-error/100542/1 "2023-06-19T05:14:28Z")

</div>

Hi I am new to this and unsure if this should be an issue to load in GitHub, but I’m not highly skilled in this level of computing.  
I am using Windows 11 Pro and XGBoost.jl (with MLJXGBoostInterface) and it was working okay with Julia 1.8 until I upgraded to 1.9.0.  
I have spent days searching reading articles and trying to figure it out including completely uninstalling Julia, removing all packages, reinstalling earlier versions I had used (Julia 1.8 through to 1.9), XGBoost (2.2.5 and 2.3.0), not using MLJ, etc., with no joy.  
Here’s my Stacktrace which TBH is not something I really understand. ☹

using XGBoost  
ERROR: InitError: UndefVarError: `libxgboost` not defined  
Stacktrace:  
[1] XGBRegisterLogCallback  
@ C:\Users\frank.julia\packages\XGBoost\sa5Xe\src\Lib.jl:56 [inlined]  
[2] **init** ()  
@ XGBoost C:\Users\frank.julia\packages\XGBoost\sa5Xe\src\XGBoost.jl:41  
[3] register\_restored\_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)  
@ Base .\loading.jl:1115  
[4] \_include\_from\_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})  
@ Base .\loading.jl:1061  
[5] \_require\_search\_from\_serialized(pkg::Base.PkgId, sourcepath::String, build\_id::UInt128)  
@ Base .\loading.jl:1506  
[6] \_require(pkg::Base.PkgId, env::String)  
@ Base .\loading.jl:1783  
[7] \_require\_prelocked(uuidkey::Base.PkgId, env::String)  
@ Base .\loading.jl:1660  
[8] macro expansion  
@ .\loading.jl:1648 [inlined]  
[9] macro expansion  
@ .\lock.jl:267 [inlined]  
[10] require(into::Module, mod::Symbol)  
@ Base .\loading.jl:1611  
during initialization of module XGBoost

---

<div class="post-metadata">

**Author:** ![simsurace](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simsurace/32/30216_2.png) [@simsurace](https://discourse.julialang.org/u/simsurace)\
**Post date:** [June 19, 2023, 6:02am UTC](https://discourse.julialang.org/t/xgboost-libxgboost-not-defined-error/100542/2 "2023-06-19T06:02:20Z")

</div>

This library is broken on Windows with Julia 1.9 due to a very arcane issue. It should be fixed on Julia nightly, please try that. The fix should be released on 1.9.2 (but I see no tag yet). This is the relevant PR: [[CompilerSupportLibraries\_jll] Upgrade to v1.0.5 by giordano · Pull Request #50135 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/50135)

---

<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:** [June 19, 2023, 7:51am UTC](https://discourse.julialang.org/t/xgboost-libxgboost-not-defined-error/100542/3 "2023-06-19T07:51:44Z")

</div>

I don’t think the issue you’re experiencing is the one mentioned by @simsurace because the symptom would be completely different (a crash at runtime). That’d still be a problem in Julia v1.9.0-1.9.1, but that’s not what you’re reporting.

Can you please show the output of

```julia
Base.BinaryPlatforms.HostPlatform()

```

?

---

<div class="post-metadata">

**Author:** ![frankd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frankd/32/50872_2.png) [@frankd](https://discourse.julialang.org/u/frankd)\
**Post date:** [June 19, 2023, 5:35pm UTC](https://discourse.julialang.org/t/xgboost-libxgboost-not-defined-error/100542/4 "2023-06-19T17:35:18Z")

</div>

Thanks Mosē; I have two versions installed because I was trying the version I was using oringally along with the latest and neither work.  
Output is:

Windows x86\_64 {cxxstring\_abi=cxx11, julia\_version=1.8.0, libgfortran\_version=5.0.0}  
and  
Windows x86\_64 {cxxstring\_abi=cxx11, julia\_version=1.9.1, libgfortran\_version=5.0.0}

Thanks Frank

---

<div class="post-metadata">

**Author:** ![frankd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frankd/32/50872_2.png) [@frankd](https://discourse.julialang.org/u/frankd)\
**Post date:** [June 19, 2023, 5:36pm UTC](https://discourse.julialang.org/t/xgboost-libxgboost-not-defined-error/100542/5 "2023-06-19T17:36:59Z")

</div>

Thanks Simone

I gave this a go and sadly didn’t work. I wasn’t that surprised as I had previously done a complete uninstall & removal of Julia and had reinstalled the original Julia version 1.80) that had worked for me before but now has the same problem regardless of Julia or XGBoost version. ☹

@giordano & @simsurace - FYI I have also tried installing libxgboost via conda, using Julia in project environments and coding in Visual Studio, Julia REPL , Pluto and JupyterLab…

Thanks Frank

---

<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:** [June 19, 2023, 6:57pm UTC](https://discourse.julialang.org/t/xgboost-libxgboost-not-defined-error/100542/7 "2023-06-19T18:57:47Z")

</div>

Uhm, if you `]add XGBoost_jll` in the same environment where you already installed `XGBoost` and the try

```julia
using XGBoost_jll
XGBoost_jll.host_platform

```

what do you get? I’m very confused, I don’t understand why you should get the error you reported at the top of the thread.

---

<div class="post-metadata">

**Author:** ![frankd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frankd/32/50872_2.png) [@frankd](https://discourse.julialang.org/u/frankd)\
**Post date:** [June 19, 2023, 7:54pm UTC](https://discourse.julialang.org/t/xgboost-libxgboost-not-defined-error/100542/8 "2023-06-19T19:54:15Z")

</div>

Thanks.  
Here’s the output, XGBoost\_jll successfully added

```julia
(@v1.8) pkg> status
Status `C:\Users\frank\.julia\environments\v1.8\Project.toml`
⌃ [add582a8] MLJ v0.19.1
⌃ [54119dfa] MLJXGBoostInterface v0.3.7
⌃ [009559a3] XGBoost v2.2.5
  [a5c6f535] XGBoost_jll v1.7.5+1

```

`using XGBoost` is okay.

However, I get the same ‘libxgboost’ error but stacktrace looks as if the problem has moved (for all three Julia):

- FYI: I am using the example from the documentation for testing [Home · XGBoost.jl (dmlc.github.io)](https://dmlc.github.io/XGBoost.jl/dev/)

````julia
julia> bst = xgboost((X, y), num_round=5, max_depth=6, objective="reg:squarederror")
ERROR: UndefVarError: libxgboost not defined
Stacktrace:
  [1] XGDMatrixCreateFromMat(data::Matrix{Float32}, nrow::Int64, ncol::Int64, missing::Float32, out::Base.RefValue{Ptr{Nothing}})
    @ XGBoost.Lib C:\Users\frank\.julia\packages\XGBoost\N1xfL\src\Lib.jl:88
  [2] xgbcall(::Function, ::Matrix{Float32}, ::Vararg{Any})
    @ XGBoost.Lib C:\Users\frank\.julia\packages\XGBoost\N1xfL\src\Lib.jl:25
  [3] #_dmatrix#9
    @ C:\Users\frank\.julia\packages\XGBoost\N1xfL\src\dmatrix.jl:183 [inlined]
  [4] DMatrix(x::Matrix{Float64}; kw::Base.Pairs{Symbol, Vector{Float64}, Tuple{Symbol}, NamedTuple{(:label,), Tuple{Vector{Float64}}}})
    @ XGBoost C:\Users\frank\.julia\packages\XGBoost\N1xfL\src\dmatrix.jl:208
  [5] #DMatrix#22
    @ C:\Users\frank\.julia\packages\XGBoost\N1xfL\src\dmatrix.jl:267 [inlined]
  [6] DMatrix
    @ C:\Users\frank\.julia\packages\XGBoost\N1xfL\src\dmatrix.jl:267 [inlined]
  [7] #DMatrix#23
    @ C:\Users\frank\.julia\packages\XGBoost\N1xfL\src\dmatrix.jl:269 [inlined]
  [8] DMatrix
    @ C:\Users\frank\.julia\packages\XGBoost\N1xfL\src\dmatrix.jl:269 [inlined]
  [9] xgboost(::Tuple{Matrix{Float64}, Vector{Float64}}; kw::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:num_round, :max_depth, :objective), Tuple{Int64, Int64, String}}})
    @ XGBoost C:\Users\frank\.julia\packages\XGBoost\N1xfL\src\booster.jl:457
 [10] top-level scope
    @ REPL[12]:1
 [11] top-level scope
    @ C:\Users\frank\.julia\packages\CUDA\pCcGc\src\initialization.jl:171 ```
````

---

<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:** [June 19, 2023, 8:16pm UTC](https://discourse.julialang.org/t/xgboost-libxgboost-not-defined-error/100542/9 "2023-06-19T20:16:53Z")

</div>

You didn’t answer my question 🙂 I’m interested in the output of `XGBoost_jll.host_platform` in the version of julia/environment where you get the error.

---

<div class="post-metadata">

**Author:** ![frankd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frankd/32/50872_2.png) [@frankd](https://discourse.julialang.org/u/frankd)\
**Post date:** [June 19, 2023, 8:25pm UTC](https://discourse.julialang.org/t/xgboost-libxgboost-not-defined-error/100542/10 "2023-06-19T20:25:42Z")

</div>

Sorry 🫣, I understand now…if in the grey box it’s a command…I’m a bit of a noob.

```julia
Windows x86_64 {cuda=12.1, cxxstring_abi=cxx11, julia_version=1.8.0, libgfortran_version=5.0.0}

```

As before, same for all Julia version.

---

<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:** [June 19, 2023, 8:39pm UTC](https://discourse.julialang.org/t/xgboost-libxgboost-not-defined-error/100542/11 "2023-06-19T20:39:01Z")

</div>

Ok, thank you very much, that was very useful, now I understand what’s going on.

@tylerjthomas9 I think the problem is that Windows platform is getting cuda tag, which we probably shouldn’t be doing at all.

---

<div class="post-metadata">

**Author:** ![frankd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frankd/32/50872_2.png) [@frankd](https://discourse.julialang.org/u/frankd)\
**Post date:** [June 19, 2023, 8:54pm UTC](https://discourse.julialang.org/t/xgboost-libxgboost-not-defined-error/100542/12 "2023-06-19T20:54:01Z")

</div>

Thank you for helping provide me a very +ve first time use of Julia Discourse 😃

1. I am assuming a long term fix means a package change, is there any chance you or @tylerjthomas9 can provide me a hack, perhaps in a .jl file or something?

2. Should I be loading this as an issue in [Issues · dmlc/XGBoost.jl (github.com)](https://github.com/dmlc/XGBoost.jl/issues)? (another first ever for me)

In the meantime, I’ll have a go at using something like Colab 🤔

Thx

---

<div class="post-metadata">

**Author:** ![tylerjthomas9](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tylerjthomas9/32/44878_2.png) [@tylerjthomas9](https://discourse.julialang.org/u/tylerjthomas9)\
**Post date:** [June 19, 2023, 9:13pm UTC](https://discourse.julialang.org/t/xgboost-libxgboost-not-defined-error/100542/13 "2023-06-19T21:13:32Z")

</div>

Can you try the nightly julia build and see if it works. Also, using XGBoost\_jll@1.7.4 should have no cuda tag on the windows build. It was added as part of the refactor to support multiple CUDA versions. I can take a look at it tonight and check.

---

<div class="post-metadata">

**Author:** ![frankd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frankd/32/50872_2.png) [@frankd](https://discourse.julialang.org/u/frankd)\
**Post date:** [June 20, 2023, 12:16am UTC](https://discourse.julialang.org/t/xgboost-libxgboost-not-defined-error/100542/14 "2023-06-20T00:16:32Z")

</div>

Apologies for taking so long to reply, my environment was messy with different versions of julia and packages so uninstalled and cleaned it all up first.  
YES 🤩, your suggestion of overnight build and XGBoost\_jll@1.7.4 worked.

Here is what I am using;

```julia
(@v1.10) pkg> status
Status `C:\Users\frank\.julia\environments\v1.10\Project.toml`
   [009559a3] XGBoost v2.3.0
⌃ [a5c6f535] XGBoost_jll v1.7.4+0
Info Packages marked with ⌃ have new versions available and may be upgradable.

```

Tested with example previously mentioned from Home · XGBoost.jl and now my own code is running fine.  
Huge relief.  
Thanks  
Frank

---

<div class="post-metadata">

**Author:** ![DaymondLing](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daymondling/32/8474_2.png) [@DaymondLing](https://discourse.julialang.org/u/DaymondLing)\
**Post date:** [June 20, 2023, 1:05am UTC](https://discourse.julialang.org/t/xgboost-libxgboost-not-defined-error/100542/15 "2023-06-20T01:05:16Z")

</div>

I had the same issue here. I tried the nightly build and XGBoost\_jll@1.7.4 and can verify that it works! Thank you very much!!

XGBoost\_jll.host\_platform:

```julia
julia> versioninfo()
Julia Version 1.10.0-DEV.1510
Commit 690a5f67c1 (2023-06-19 19:23 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 16 × AMD Ryzen 7 3700X 8-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, znver2)
  Threads: 23 on 16 virtual cores
Environment:
  JULIA_NUM_THREADS = auto

(@v1.10) pkg> st
Status `C:\Users\Daymond\.julia\environments\v1.10\Project.toml`
  [009559a3] XGBoost v2.3.0
⌃ [a5c6f535] XGBoost_jll v1.7.4+0
Info Packages marked with ⌃ have new versions available and may be upgradable.

julia> using XGBoost_jll

julia> XGBoost_jll.host_platform
Windows x86_64 {cuda=12.1, cxxstring_abi=cxx11, julia_version=1.10.0, libgfortran_version=5.0.0}

```

Running XGBoost:

```julia
julia> using XGBoost

julia> (X, y) = (randn(100,4), randn(100))
([-0.2623242551305721 -0.7349016916372322 -0.12226910711070484 -1.7262374695698632; 0.8933518985340615 -1.0466514268113587 -1.2625763832961918 0.5165072356427121; … ; 1.0389513791819174 0.5070140641914969 0.250096316841046 0.8411149909580441; -0.06475505384999933 1.1945917760920695 0.683202330789277 0.6970125676128226], [0.26426235528171105, 0.8589844858085923, -0.2937243715578777, -0.45293466098853175, 0.3352454222015448, -0.044283648660174146, -0.9737646611540043, -1.472423862819522, 1.0827540869930354, -0.18105464988479517 … -0.289517450801958, 0.030952382769496706, 0.34658208038935573, -1.0541588807051363, 0.4672706118266623, -0.2843188714799799, -1.7266824152048368, -0.5690021912345585, -0.8951092383731294, 0.42586554568021784])

julia> bst = xgboost((X, y), num_round=5, max_depth=6, objective="reg:squarederror")
[ Info: XGBoost: starting training.
[Info: [1] train-rmse:0.89970133211933134
[Info: [2] train-rmse:0.74107146090429576
[Info: [3] train-rmse:0.63458998856155557
[Info: [4] train-rmse:0.54164823654162086
[Info: [5] train-rmse:0.48739732068195674
[ Info: Training rounds complete.
Booster()

```
