Gurobi.jl icon indicating copy to clipboard operation
Gurobi.jl copied to clipboard

A recommendation for code revision

Open Yue-Wang-qvp opened this issue 2 years ago • 10 comments

I suggest to revise the build.jl like this " const ALIASES = [ "gurobi100", "gurobi95", "gurobi91", "gurobi90" ]

paths_to_try = [] "

The reason is that the original piece of code "paths_to_try = copy(ALIASES)" will result in the library handle variable like "libgurobi = gurobi100". Such a handle variable does not include the absolute path and makes a compiled package with "Gurobi.jl" throw error of "ErrorException("could not load library "gurobi 100"".

Yue-Wang-qvp avatar Apr 15 '23 11:04 Yue-Wang-qvp

and makes a compiled package with "Gurobi.jl"

What do you mean by "compiled"?

We need the code as-is, because many users have Gurobi on their PATH and haven't set the GUROBI_HOME environment variable.

When building Gurobi, we'll only write out the library path as gurobi100 if it exists on the PATH, so if you're running into issues after this, then you've probably removed Gurobi from PATH. Just re-add it.

odow avatar Apr 16 '23 20:04 odow

I indeed have GUROBI_HOME environment variable and also the directory of 'gurobi100' in the Path, so I am able to successfully call for gurobi100.dll in my package or any other Julia script .jl. However, after I use PackageCompiler.create_library() to create a standalone APP from my package, running the APP will throw an error containing the prompt of ErrorException("could not load library "gurobi 100". I am not familiar with the mechanism of PackageCompiler.create_library(), and have to modify the code of Gurobi.jl to be paths_to_try = [] after many attempts. Such a modification succeed in directing the APP to find the gurobi100.dll.

Yue-Wang-qvp avatar Apr 18 '23 08:04 Yue-Wang-qvp

Once you have the app, it should still work if Gurobi is on your PATH. Did you run the binary from a difference computer where Gurobi wasn't on the PATH?

@joaquimg is the person with experience doing this and may have some suggestions.

odow avatar Apr 18 '23 21:04 odow

The strange question is that the compiled APP can even not succeed on my own computer, and the slight modification of "paths_to_try = []" can solve it perfectly.

Yue-Wang-qvp avatar Apr 20 '23 07:04 Yue-Wang-qvp

But presumably if you set paths_to_try = [] it will end up hard-coding the path to your libgurobi, and then if you move computers that won't work either?

odow avatar Apr 20 '23 08:04 odow

No, the app can be executed successfully in another computer which even has different version of Gurobi installed, provided that paths_to_try = [] was used when compiling the app

Yue-Wang-qvp avatar Apr 26 '23 07:04 Yue-Wang-qvp

Is it a linux machine? If so, when paths_to_try=[], your first machine is not using the local version of Gurobi, and when you move it to the new machine, it also downloads the artifact:

https://github.com/jump-dev/Gurobi.jl/blob/7145c2875fd0945e14c908a715d99ceb65a7c4f2/src/Gurobi.jl#L16-L23

If you leave paths_to_try unmodified, then your first machine is finding libgurobi on the system path, and then it can't find Gurobi on the new machine. If the binary doesn't work on the original machine either, then the binary must be mucking with the PATH, but I don't know why or the details of how to fix.

If you want to run on linux only, then I'd suggest removing Gurobi from the path before compiling.

odow avatar Apr 26 '23 07:04 odow

Any updates on this?

odow avatar May 16 '23 23:05 odow

I am runing windows

Yue-Wang-qvp avatar May 19 '23 10:05 Yue-Wang-qvp

See https://julialang.github.io/PackageCompiler.jl/dev/devdocs/relocatable_part_3.html#Relocatability-of-Julia-packages

PackageCompiler currently does not work well with packages which require hard-code paths for external binaries.

The best work-around is probably to have gurobi100 in your PATH of the build machine so that it gets written to deps.jl, and then set a similar PATH in the deployment machine.

odow avatar Feb 17 '24 04:02 odow

The new version of Gurobi.jl uses binaries provided by Gurobi_jll, so it should work by default on any machine that has a valid Gurobi license. You do not need to manually install or specify the path in the build step.

odow avatar May 22 '24 23:05 odow