BuildExecutable throws unhelpul error message when when output is sent to STDERR during compile.
Closed this issue · 2 comments
haberdashPI commented
I was just trying to see if it was possible to use this to compile a simple mathematical optimization problem, and found that the example Sudoku solver on the JuMP.jl website does not compile. The error reported is a problem with not be able to find the STDERR variable. I've checked and this runs when I just call main from julia.
I'm using Julia version 0.4.5, and BuildExecutable version 0.0.3.
Here is my attempt:
import JuMP
function main()
# Create a model
sudoku = JuMP.Model()
# Create our variables
@JuMP.defVar(sudoku, x[i=1:9, j=1:9, k=1:9], Bin)
for i = 1:9, j = 1:9 # Each row and each column
# Sum across all the possible digits
# One and only one of the digits can be in this cell,
# so the sum must be equal to one
@JuMP.addConstraint(sudoku, sum{x[i,j,k],k=1:9} == 1)
end
for ind = 1:9 # Each row, OR each column
for k = 1:9 # Each digit
# Sum across columns (j) - row constraint
@JuMP.addConstraint(sudoku, sum{x[ind,j,k],j=1:9} == 1)
# Sum across rows (i) - column constraint
@JuMP.addConstraint(sudoku, sum{x[i,ind,k],i=1:9} == 1)
end
end
for i = 1:3:7, j = 1:3:7, k = 1:9
# i is the top left row, j is the top left column
# We'll sum from i to i+2, e.g. i=4, r=4, 5, 6
@JuMP.addConstraint(sudoku, sum{x[r,c,k], r=i:i+2, c=j:j+2} == 1)
end
init_sol = [ 5 3 0 0 7 0 0 0 0;
6 0 0 1 9 5 0 0 0;
0 9 8 0 0 0 0 6 0;
8 0 0 0 6 0 0 0 3;
4 0 0 8 0 3 0 0 1;
7 0 0 0 2 0 0 0 6;
0 6 0 0 0 0 2 8 0;
0 0 0 4 1 9 0 0 5;
0 0 0 0 8 0 0 7 9]
for i = 1:9, j = 1:9
# If the space isn't empty
if init_sol[i,j] != 0
# Then the corresponding variable for that digit
# and location must be 1
@JuMP.addConstraint(sudoku, x[i,j,init_sol[i,j]] == 1)
end
end
JuMP.solve(sudoku)
# Extract the values of x
x_val = JuMP.getValue(x)
# Create a matrix to store the solution
sol = zeros(Int,9,9) # 9x9 matrix of integers
for i in 1:9, j in 1:9, k in 1:9
# Integer programs are solved as a series of linear programs
# so the values might not be precisely 0 and 1. We can just
# round them to the nearest integer to make it easier
if iround(x_val[i,j,k]) == 1
sol[i,j] = k
end
end
# Display the solution
println(sol)
end
Here's the error:
LoadError(at "sysimg.jl" line 319: LoadError(at "/Applications/Julia-0.4.5.app/Contents/Resources/julia/share/julia/base/userimg.jl" line 1: LoadError(at "/Users/davidlittle/main.jl" line 67: UndefVarError(var=:STDERR))))
rec_backtrace at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/task.c:658
eval at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:322
jl_parse_eval_all at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/toplevel.c:577
jl_load at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/toplevel.c:620
include at boot.jl:261
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia.h:1331
include_from_node1 at loading.jl:320
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia.h:1331
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:56
eval at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:230
jl_toplevel_eval_flex at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/toplevel.c:527
jl_parse_eval_all at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/toplevel.c:577
jl_load at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/toplevel.c:620
include at boot.jl:261
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia.h:1331
include_from_node1 at loading.jl:320
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia.h:1331
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:56
eval at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:230
eval_body at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:581
jl_toplevel_eval_body at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:545
jl_toplevel_eval_flex at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/toplevel.c:521
jl_parse_eval_all at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/toplevel.c:577
jl_load at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/toplevel.c:620
exec_program at /Applications/Julia-0.4.5.app/Contents/Resources/julia/bin/julia (unknown line)
true_main at /Applications/Julia-0.4.5.app/Contents/Resources/julia/bin/julia (unknown line)
main at /Applications/Julia-0.4.5.app/Contents/Resources/julia/bin/julia (unknown line)
haberdashPI commented
After doing a little digging this appears to happen due the deprecation warnings generated by the code I copy-pasted from the JuMP website. If I remove these warnings, the compilation completes without throwing an error.
dhoegh commented
This is fixed when using Julia-0.5.