# LoadError: UndefVarError: \`libglpk\` not defined

**URL:** <https://discourse.julialang.org/t/loaderror-undefvarerror-libglpk-not-defined/110480>\
**Category:** Optimization (Mathematical)\
**Created:** [February 20, 2024, 9:56pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-libglpk-not-defined/110480 "2024-02-20T21:56:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carl\_Baier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carl_baier/32/50996_2.png) [@Carl\_Baier](https://discourse.julialang.org/u/Carl_Baier)\
**Post date:** [February 20, 2024, 9:56pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-libglpk-not-defined/110480/1 "2024-02-20T21:56:30Z")

</div>

Hello, i have this code:

```julia
using libglpk
using GLPK
using JuMP
using Gurobi
using DataFrames
using BlockDecomposition, Coluna;

I_list = [1, 2, 3]
T_list = [1, 2, 3, 4, 5, 6, 7]
K_list = [1, 2, 3]
alpha=0.01
M = 10000
Max = 6

I_list1 = DataFrame(I = I_list)
T_list1 = DataFrame(T = T_list)
K_list1 = DataFrame(K = K_list)

Demand_Dict = Dict(
    (1, 1) => 2, (1, 2) => 1, (1, 3) => 0,
    (2, 1) => 1, (2, 2) => 2, (2, 3) => 0,
    (3, 1) => 1, (3, 2) => 1, (3, 3) => 1,
    (4, 1) => 1, (4, 2) => 2, (4, 3) => 0,
    (5, 1) => 2, (5, 2) => 0, (5, 3) => 1,
    (6, 1) => 1, (6, 2) => 1, (6, 3) => 1,
    (7, 1) => 0, (7, 2) => 3, (7, 3) => 0
)

# Create the model
model = Model(Gurobi.Optimizer)

# Decision variables
@variable(model, slack[t in T_list, s in K_list] >= 0)
@variable(model, motivation[i in I_list, t in T_list, s in K_list], Bin)
@variable(model, mood[i in I_list, t in T_list] >= 0)
@variable(model, x[i in I_list, t in T_list, s in K_list] >= 0)

# Objective function
@objective(model, Min, sum(slack[t, s] for t in T_list, s in K_list))

# Constraints for demand
for (t, s) in keys(Demand_Dict)
    @constraint(model, slack[t, s] >= Demand_Dict[(t, s)] - sum(motivation[i, t, s] for i in I_list))
end

for i in I_list
    for t in T_list
        @constraint(model, mood[i, t] == 1 - alpha * sum(x[i, t, s] for s in K_list))
        @constraint(model, sum(x[i, t, s] for s in K_list) <= 1)
        for s in K_list
            @constraint(model, mood[i, t] + M*(1-x[i, t, s]) >= motivation[i, t, s])
            @constraint(model, motivation[i, t, s] >= mood[i, t] - M * (1 - x[i, t, s]))
            @constraint(model, motivation[i, t, s] <= x[i, t, s])
        end
    end
    for t in 1:(length(T_list) - Max)
        @constraint(model, sum(x[i, u, s] for s in K_list for u in t:(t + Max)) <= Max)
    end
end

# Solve the model
optimize!(model)

# Coluna
coluna = optimizer_with_attributes(
    Coluna.Optimizer,
    "params" => Coluna.Params(
        solver = Coluna.Algorithm.TreeSearchAlgorithm() # default branch-cut-and-price
    ),
    "default_optimizer" => GLPK.Optimizer # GLPK for the master & the subproblems
);

@axis(M_axis, I_list);

model = BlockModel(coluna; direct_model = true);
@dantzig_wolfe_decomposition(model, decomposition, M_axis)

master = getmaster(decomposition)
subproblems = getsubproblems(decomposition)

specify!.(subproblems, lower_multiplicity = 0, upper_multiplicity = 1)
getsubproblems(decomposition)

```

optimize!(model)

and i am currently running into this error:

`LoadError: UndefVarError: `libglpk` not defined`

I did install libglpk correctly, but it doesnt seem to work. How can i fix this error?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 20, 2024, 10:01pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-libglpk-not-defined/110480/2 "2024-02-20T22:01:47Z")

</div>

Remove `using libglpk`. You shouldn’t need this.

Was there a tutorial that suggested the line of code? We should fix the tutorial.

---

<div class="post-metadata">

**Author:** ![Carl\_Baier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carl_baier/32/50996_2.png) [@Carl\_Baier](https://discourse.julialang.org/u/Carl_Baier)\
**Post date:** [February 20, 2024, 10:20pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-libglpk-not-defined/110480/3 "2024-02-20T22:20:58Z")

</div>

I just did! However, i still run into ths error

```julia
WARNING: could not import GLPK_jll.libglpk into GLPK
ERROR: LoadError: UndefVarError: `libglpk` not defined
Stacktrace:
 [1] glp_version()
   @ GLPK ~/.julia/packages/GLPK/JpN1q/src/gen/libglpk_api.jl:678
 [2] top-level scope
   @ ~/.julia/packages/GLPK/JpN1q/src/GLPK.jl:35
 [3] include
   @ ./Base.jl:495 [inlined]
 [4] 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, UInt128}}, source::Nothing)
   @ Base ./loading.jl:2222
 [5] top-level scope
   @ stdin:3
in expression starting at /Users/..../.julia/packages/GLPK/JpN1q/src/GLPK.jl:1
in expression starting at stdin:3
  ✗ BinaryProvider
  ✗ GLPK
  0 dependencies successfully precompiled in 2 seconds. 27 already precompiled.

ERROR: The following 1 direct dependency failed to precompile:

GLPK [60bf3e95-4087-53dc-ae20-288a0d20c6a6]

Failed to precompile GLPK [60bf3e95-4087-53dc-ae20-288a0d20c6a6] to "/Users/.../.julia/compiled/v1.10/GLPK/jl_ttVBsB".
WARNING: could not import GLPK_jll.libglpk into GLPK
ERROR: LoadError: UndefVarError: `libglpk` not defined

```

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 20, 2024, 10:29pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-libglpk-not-defined/110480/4 "2024-02-20T22:29:23Z")

</div>

What is `import Pkg; Pkg.status()` and `versioninfo()`?

It looks like you might be using an old version of GLPK and an M2 Mac?

You need a recent version of GLPK (e.g., v1.0.0 or newer) to use GLPK on Apple Silicon.

---

<div class="post-metadata">

**Author:** ![Carl\_Baier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carl_baier/32/50996_2.png) [@Carl\_Baier](https://discourse.julialang.org/u/Carl_Baier)\
**Post date:** [February 20, 2024, 10:45pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-libglpk-not-defined/110480/5 "2024-02-20T22:45:34Z")

</div>

Where do I need to run these commands? Sorry I am fairly new to Julia

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 20, 2024, 10:47pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-libglpk-not-defined/110480/6 "2024-02-20T22:47:40Z")

</div>

In the REPL. Here’s what I see:

```julia
julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39b (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (x86_64-apple-darwin22.4.0)
  CPU: 8 × Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
  Threads: 1 on 8 virtual cores

julia> import Pkg; Pkg.status()
Status `~/.julia/environments/v1.10/Project.toml`
  [6e4b80f9] BenchmarkTools v1.4.0
⌃ [35a29f4d] DocumenterTools v0.1.18
⌃ [98e50ef6] JuliaFormatter v1.0.45
  [85b6ec6f] MethodAnalysis v0.4.13
⌃ [295af30f] Revise v3.5.12
Info Packages marked with ⌃ have new versions available and may be upgradable.

```

---

<div class="post-metadata">

**Author:** ![Carl\_Baier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carl_baier/32/50996_2.png) [@Carl\_Baier](https://discourse.julialang.org/u/Carl_Baier)\
**Post date:** [February 20, 2024, 11:04pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-libglpk-not-defined/110480/7 "2024-02-20T23:04:59Z")

</div>

> [@odow](#):
>
> versioninfo()

```julia
julia> versioninfo()
Julia Version 1.10.1
Commit 7790d6f0641 (2024-02-13 20:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS =

```

and

```julia
julia> import Pkg; Pkg.status() 
Status `~/.julia/environments/v1.10/Project.toml`
⌅ [6cde8614] BlockDecomposition v1.4.0
⌃ [88b4ec78] Coluna v0.3.12
  [a93c6f00] DataFrames v1.6.1
⌃ [60bf3e95] GLPK v0.14.14
⌃ [2e9cd046] Gurobi v0.9.14
⌅ [4076af6c] JuMP v0.21.10
Info Packages marked with ⌃ and ⌅ have new versions available. Those with ⌃ may be upgradable, but those with ⌅ are restricted by compatibility constraints from upgrading. To see why use `status --outdated

```

And i am using a M1 Mac

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 20, 2024, 11:16pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-libglpk-not-defined/110480/8 "2024-02-20T23:16:52Z")

</div>

You’ve installed some old versions of the packages that don’t support M1 (because they were released before M1 came out 😄).

Try `import Pkg; Pkg.update()`.

You’ll need GLPK, Gurobi, and JuMP at least version 1, and Coluna v0.8.0 or v0.8.1.

Here are the versions I get if I install in a fresh environment:

```Julia
(tmp) pkg> add BlockDecomposition Coluna DataFrames GLPK Gurobi JuMP

(tmp) pkg> st
Status `/private/tmp/Project.toml`
[6cde8614] BlockDecomposition v1.15.0
[88b4ec78] Coluna v0.8.1
[a93c6f00] DataFrames v1.6.1
[60bf3e95] GLPK v1.1.3
[2e9cd046] Gurobi v1.2.1
[4076af6c] JuMP v1.20.0

```
