# Nlopt, stogo, on windows, doesnt work

**URL:** <https://discourse.julialang.org/t/nlopt-stogo-on-windows-doesnt-work/3080>\
**Category:** General Usage\
**Created:** [April 6, 2017, 1:55am UTC](https://discourse.julialang.org/t/nlopt-stogo-on-windows-doesnt-work/3080 "2017-04-06T01:55:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![flomenbom](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flomenbom](https://discourse.julialang.org/u/flomenbom)\
**Post date:** [April 6, 2017, 1:55am UTC](https://discourse.julialang.org/t/nlopt-stogo-on-windows-doesnt-work/3080/1 "2017-04-06T01:55:52Z")

</div>

The nlopt algorithms, on windows  
GD\_STOGO & GD\_STOGO\_RAND  
do not work

The website about nlopt said  
"StoGO is written in C++, which means that it is only included when you compile the C++ algorithms enabled, in which case (on Unix) you must link to -lnlopt\_cxx instead of -lnlopt. "

in other website they talked about installing camke and connecting the path, and setting BUILD\_ON WINDOWS to 1  
where to update the BUILD\_ON\_WINDOWS??

---

<div class="post-metadata">

**Author:** ![Zhong\_Pan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhong_pan/32/19872_2.png) [@Zhong\_Pan](https://discourse.julialang.org/u/Zhong_Pan)\
**Post date:** [April 6, 2017, 9:45pm UTC](https://discourse.julialang.org/t/nlopt-stogo-on-windows-doesnt-work/3080/2 "2017-04-06T21:45:32Z")

</div>

BUILD\_ON\_WINDOWS is an environmental variable you need to create. To do that, open Windows Explorer, right click on “This PC” or “My Computer” (depending on Windows version), click “Properties”, click “Advanced system settings”, click “Environment Variables…”, on the bottom half (“System variables” panel), click “New…”, type BUILD\_ON\_WINDOWS as “Variable name”, and 1 as “Variable value”, then click OK.

---

<div class="post-metadata">

**Author:** ![flomenbom](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flomenbom](https://discourse.julialang.org/u/flomenbom)\
**Post date:** [April 7, 2017, 1:29am UTC](https://discourse.julialang.org/t/nlopt-stogo-on-windows-doesnt-work/3080/3 "2017-04-07T01:29:28Z")

</div>

thanks, there’s still work  
what is the code to work with c++ libraries, such that nlopt will work, with that function  
in the stogo algorithm, that call c++ libraries??

there are various pages, about that  
[https://github.com/JuliaOpt/NLopt.jl/pull/4](https://github.com/JuliaOpt/NLopt.jl/pull/4)  
[https://github.com/JuliaOpt/NLopt.jl/pull/4/commits/3e3722c513e0a3bfb3e1061e80b383edc92961da](https://github.com/JuliaOpt/NLopt.jl/pull/4/commits/3e3722c513e0a3bfb3e1061e80b383edc92961da)  
[https://github.com/JuliaLang/BinDeps.jl/issues/55](https://github.com/JuliaLang/BinDeps.jl/issues/55)  
[https://github.com/JuliaOpt/NLopt.jl/pull/4/commits/020f3a8af423709e6dc78f32c5d9bd3178898af6](https://github.com/JuliaOpt/NLopt.jl/pull/4/commits/020f3a8af423709e6dc78f32c5d9bd3178898af6)

yet these are pages from developers 4 years ago  
and the question is how to install in windows  
the nlopt such that c++ compiler will work in calling to Stogo??

---

<div class="post-metadata">

**Author:** ![Zhong\_Pan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhong_pan/32/19872_2.png) [@Zhong\_Pan](https://discourse.julialang.org/u/Zhong_Pan)\
**Post date:** [April 7, 2017, 11:30am UTC](https://discourse.julialang.org/t/nlopt-stogo-on-windows-doesnt-work/3080/4 "2017-04-07T11:30:52Z")

</div>

Interesting. I wonder why you had to build NLopt in the first place. Maybe you were actually having difficulties in building one of its dependencies?

The NLopt GitHub page says,

```julia
Installation

Within Julia, you can install the NLopt.jl package with the package manager: Pkg.add("NLopt")

On Windows and OS X platforms, NLopt binaries will be automatically installed. On other platforms, Julia will attempt to build NLopt from source; be sure to have a compiler installed.

```

So I tried it on my JuliaPro 0.5.1 and it worked.

```julia
julia> Pkg.add("NLopt")
INFO: Cloning cache of NLopt from https://github.com/JuliaOpt/NLopt.jl.git
INFO: Downgrading LightGraphs: v0.7.5 => v0.7.3
INFO: Installing NLopt v0.3.4
INFO: Building WinRPM
INFO: Downloading https://cache.julialang.org/http://download.opensuse.org/repositories/windows:/mingw:/win32/openSUSE_42.2/repodata/repomd.xml
INFO: Downloading https://cache.julialang.org/http://download.opensuse.org/repositories/windows:/mingw:/win64/openSUSE_42.2/repodata/repomd.xml
INFO: Downloading https://cache.julialang.org/http://download.opensuse.org/repositories/windows:/mingw:/win64/openSUSE_42.2/repodata/c03a4ad43b0ddeef0d41a248e15e2ec8339e0d26a5e5585e420c119145e48a1e-primary.xml.gz
INFO: Building EzXML
INFO: Packages to update: zlib1, libxml2-2
INFO: Downloading: zlib1
INFO: Extracting: zlib1
INFO: Downloading: libxml2-2
INFO: Extracting: libxml2-2
INFO: Complete
INFO: Building Rmath
INFO: Building Blosc
INFO: Building HDF5
INFO: Updating WinRPM package list
INFO: Downloading https://cache.julialang.org/http://download.opensuse.org/repositories/windows:/mingw:/win32/openSUSE_42.2/repodata/repomd.xml
INFO: Downloading https://cache.julialang.org/http://download.opensuse.org/repositories/windows:/mingw:/win64/openSUSE_42.2/repodata/repomd.xml
INFO: Building NLopt
INFO: Attempting to Create directory C:\JuliaPro\pkgs-0.5.1.1\v0.5\NLopt\deps\downloads
INFO: Downloading file http://ab-initio.mit.edu/nlopt/nlopt-2.4.1-dll32.zip
INFO: Done downloading file http://ab-initio.mit.edu/nlopt/nlopt-2.4.1-dll32.zip
INFO: Attempting to Create directory C:\JuliaPro\pkgs-0.5.1.1\v0.5\NLopt\deps\downloads
INFO: Directory C:\JuliaPro\pkgs-0.5.1.1\v0.5\NLopt\deps\downloads already created
INFO: Downloading file http://ab-initio.mit.edu/nlopt/nlopt-2.4.1-dll64.zip
INFO: Done downloading file http://ab-initio.mit.edu/nlopt/nlopt-2.4.1-dll64.zip
INFO: Attempting to Create directory C:\JuliaPro\pkgs-0.5.1.1\v0.5\NLopt\deps\src
INFO: Attempting to Create directory C:\JuliaPro\pkgs-0.5.1.1\v0.5\NLopt\deps\src\w32
INFO: Attempting to Create directory C:\JuliaPro\pkgs-0.5.1.1\v0.5\NLopt\deps\src\w64
INFO: Attempting to Create directory C:\JuliaPro\pkgs-0.5.1.1\v0.5\NLopt\deps\src
INFO: Directory C:\JuliaPro\pkgs-0.5.1.1\v0.5\NLopt\deps\src already created

7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18

Processing archive: C:\JuliaPro\pkgs-0.5.1.1\v0.5\NLopt\deps\downloads\nlopt-2.4.1-dll32.zip

Extracting libnlopt-0.dll
Extracting libnlopt-0.def
Extracting nlopt.f
Extracting nlopt.h
Extracting nlopt.hpp
Extracting nlopt.py
Extracting nlopt-python.cpp
Extracting setup.py
Extracting README
Extracting COPYING
Extracting COPYRIGHT
Extracting NEWS
Extracting README-WINDOWS
Extracting matlab\NLOPT_AUGLAG_EQ.m
Extracting matlab\NLOPT_AUGLAG.m
Extracting matlab\NLOPT_GD_MLSL_LDS.m
Extracting matlab\NLOPT_GD_MLSL.m
Extracting matlab\NLOPT_GD_STOGO.m
Extracting matlab\NLOPT_GD_STOGO_RAND.m
Extracting matlab\NLOPT_G_MLSL_LDS.m
Extracting matlab\NLOPT_G_MLSL.m
Extracting matlab\NLOPT_GN_CRS2_LM.m
Extracting matlab\NLOPT_GN_DIRECT_L.m
Extracting matlab\NLOPT_GN_DIRECT_L_NOSCAL.m
Extracting matlab\NLOPT_GN_DIRECT_L_RAND.m
Extracting matlab\NLOPT_GN_DIRECT_L_RAND_NOSCAL.m
Extracting matlab\NLOPT_GN_DIRECT.m
Extracting matlab\NLOPT_GN_DIRECT_NOSCAL.m
Extracting matlab\NLOPT_GN_ESCH.m
Extracting matlab\NLOPT_GN_ISRES.m
Extracting matlab\NLOPT_GN_MLSL_LDS.m
Extracting matlab\NLOPT_GN_MLSL.m
Extracting matlab\NLOPT_GN_ORIG_DIRECT_L.m
Extracting matlab\NLOPT_GN_ORIG_DIRECT.m
Extracting matlab\NLOPT_LD_AUGLAG_EQ.m
Extracting matlab\NLOPT_LD_AUGLAG.m
Extracting matlab\NLOPT_LD_CCSAQ.m
Extracting matlab\NLOPT_LD_LBFGS.m
Extracting matlab\NLOPT_LD_LBFGS_NOCEDAL.m
Extracting matlab\NLOPT_LD_MMA.m
Extracting matlab\NLOPT_LD_SLSQP.m
Extracting matlab\NLOPT_LD_TNEWTON.m
Extracting matlab\NLOPT_LD_TNEWTON_PRECOND.m
Extracting matlab\NLOPT_LD_TNEWTON_PRECOND_RESTART.m
Extracting matlab\NLOPT_LD_TNEWTON_RESTART.m
Extracting matlab\NLOPT_LD_VAR1.m
Extracting matlab\NLOPT_LD_VAR2.m
Extracting matlab\NLOPT_LN_AUGLAG_EQ.m
Extracting matlab\NLOPT_LN_AUGLAG.m
Extracting matlab\NLOPT_LN_BOBYQA.m
Extracting matlab\NLOPT_LN_COBYLA.m
Extracting matlab\NLOPT_LN_NELDERMEAD.m
Extracting matlab\NLOPT_LN_NEWUOA_BOUND.m
Extracting matlab\NLOPT_LN_NEWUOA.m
Extracting matlab\NLOPT_LN_PRAXIS.m
Extracting matlab\NLOPT_LN_SBPLX.m
Extracting matlab\nlopt_minimize_constrained.m
Extracting matlab\nlopt_minimize.m
Extracting matlab\nlopt_optimize.c
Extracting matlab\nlopt_optimize.m

Everything is Ok

Files: 60
Size: 1602081
Compressed: 495108
INFO: Attempting to Create directory C:\JuliaPro\pkgs-0.5.1.1\v0.5\NLopt\deps\src
INFO: Directory C:\JuliaPro\pkgs-0.5.1.1\v0.5\NLopt\deps\src already created

7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18

Processing archive: C:\JuliaPro\pkgs-0.5.1.1\v0.5\NLopt\deps\downloads\nlopt-2.4.1-dll64.zip

Extracting libnlopt-0.dll
Extracting libnlopt-0.def
Extracting nlopt.f
Extracting nlopt.h
Extracting nlopt.hpp
Extracting nlopt.py
Extracting nlopt-python.cpp
Extracting setup.py
Extracting README
Extracting COPYING
Extracting COPYRIGHT
Extracting NEWS
Extracting README-WINDOWS
Extracting matlab\NLOPT_AUGLAG_EQ.m
Extracting matlab\NLOPT_AUGLAG.m
Extracting matlab\NLOPT_GD_MLSL_LDS.m
Extracting matlab\NLOPT_GD_MLSL.m
Extracting matlab\NLOPT_GD_STOGO.m
Extracting matlab\NLOPT_GD_STOGO_RAND.m
Extracting matlab\NLOPT_G_MLSL_LDS.m
Extracting matlab\NLOPT_G_MLSL.m
Extracting matlab\NLOPT_GN_CRS2_LM.m
Extracting matlab\NLOPT_GN_DIRECT_L.m
Extracting matlab\NLOPT_GN_DIRECT_L_NOSCAL.m
Extracting matlab\NLOPT_GN_DIRECT_L_RAND.m
Extracting matlab\NLOPT_GN_DIRECT_L_RAND_NOSCAL.m
Extracting matlab\NLOPT_GN_DIRECT.m
Extracting matlab\NLOPT_GN_DIRECT_NOSCAL.m
Extracting matlab\NLOPT_GN_ESCH.m
Extracting matlab\NLOPT_GN_ISRES.m
Extracting matlab\NLOPT_GN_MLSL_LDS.m
Extracting matlab\NLOPT_GN_MLSL.m
Extracting matlab\NLOPT_GN_ORIG_DIRECT_L.m
Extracting matlab\NLOPT_GN_ORIG_DIRECT.m
Extracting matlab\NLOPT_LD_AUGLAG_EQ.m
Extracting matlab\NLOPT_LD_AUGLAG.m
Extracting matlab\NLOPT_LD_CCSAQ.m
Extracting matlab\NLOPT_LD_LBFGS.m
Extracting matlab\NLOPT_LD_LBFGS_NOCEDAL.m
Extracting matlab\NLOPT_LD_MMA.m
Extracting matlab\NLOPT_LD_SLSQP.m
Extracting matlab\NLOPT_LD_TNEWTON.m
Extracting matlab\NLOPT_LD_TNEWTON_PRECOND.m
Extracting matlab\NLOPT_LD_TNEWTON_PRECOND_RESTART.m
Extracting matlab\NLOPT_LD_TNEWTON_RESTART.m
Extracting matlab\NLOPT_LD_VAR1.m
Extracting matlab\NLOPT_LD_VAR2.m
Extracting matlab\NLOPT_LN_AUGLAG_EQ.m
Extracting matlab\NLOPT_LN_AUGLAG.m
Extracting matlab\NLOPT_LN_BOBYQA.m
Extracting matlab\NLOPT_LN_COBYLA.m
Extracting matlab\NLOPT_LN_NELDERMEAD.m
Extracting matlab\NLOPT_LN_NEWUOA_BOUND.m
Extracting matlab\NLOPT_LN_NEWUOA.m
Extracting matlab\NLOPT_LN_PRAXIS.m
Extracting matlab\NLOPT_LN_SBPLX.m
Extracting matlab\nlopt_minimize_constrained.m
Extracting matlab\nlopt_minimize.m
Extracting matlab\nlopt_optimize.c
Extracting matlab\nlopt_optimize.m

Everything is Ok

Files: 60
Size: 1932764
Compressed: 541555
INFO: Attempting to Create directory C:\JuliaPro\pkgs-0.5.1.1\v0.5\NLopt\deps\usr\lib
INFO: Package database updated
INFO: METADATA is out-of-date — you may not have the latest version of NLopt
INFO: Use `Pkg.update()` to get the latest versions of your packages

```

Notice these lines:

```julia
...
Processing archive: C:\JuliaPro\pkgs-0.5.1.1\v0.5\NLopt\deps\downloads\nlopt-2.4.1-dll32.zip
...
Processing archive: C:\JuliaPro\pkgs-0.5.1.1\v0.5\NLopt\deps\downloads\nlopt-2.4.1-dll64.zip
...

```

These show during the installation the NLopt Windows binaries are downloaded directly from server, not built locally.

If you still have difficulty in building something, can you

- Make sure the system has Visual Studio 2015 (aka Visual Studio 14) installed (community edition ISO download link can be found [here](https://gist.github.com/CHEF-KOCH/8078b39e1aad71ef6c317a3c0edb6ec9)), and Visual C++ has been installed. Note: By default installing Visual Studio only gives you C# and VB. User must select Visual C++ to be installed.

- Make sure CMake has been installed ([download link](https://cmake.org/download/)), and its bin folder is included in the environmental variable PATH. For example, if the installation path is C:\CMake, then C:\CMake\bin should be included in PATH - the installer would add it automatically.

- Create an environmental variable BUILD\_ON\_WINDOWS with the value 1.

---

<div class="post-metadata">

**Author:** ![flomenbom](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flomenbom](https://discourse.julialang.org/u/flomenbom)\
**Post date:** [April 8, 2017, 4:32am UTC](https://discourse.julialang.org/t/nlopt-stogo-on-windows-doesnt-work/3080/5 "2017-04-08T04:32:19Z")

</div>

THANKS, perfromed the 3 steps , uninstalled and reinstalled Nopt  
yet still the algorithm GD\_STOGO\_RAND  
did not work

the others algirthms work alright,  
where here we are seeing that there is a problme

the error is

ArgumentError: invalid NLopt arguments  
…lines 532, … 529, … 276, … 259

The same call to the optimizer worked to all the others algorithms  
where i just changed the name of the algorithm  
to the STOGO  
and the error appeared

in case you work with windows,  
can you check the algorithm STOGO ??  
just run the following

using NLopt  
x0=[1.1,2.3,3.2]

```
function f_34(x::Vector{Float64},gr_::Vector{Float64})
    F_=3+(x[1]-1)^2+x[2]*(x[3]+3)
 if (length(gr_)>0)
    gr_[1]=2*x[1]
    gr_[2]=x[3]+3
    gr_[3]=x[2]
  end
    return abs(F_) ; end

opt = NLopt.Opt(:GD_STOGO_RAND , length(x0))
NLopt.min_objective!(opt::NLopt.Opt, (x, g_) ->f_34(x,g_) )
#NLopt.inequality_constraint!(opt, (x, g) -> LkCon_model_2st(x, g, Y), 0.204)
NLopt.xtol_rel!(opt::NLopt.Opt,0.00204)
NLopt.ftol_rel!(opt::NLopt.Opt,0.0204)
NLopt.maxeval!(opt::NLopt.Opt, 1500*4*3)
  NLopt.lower_bounds!(opt::NLopt.Opt, -[50,50,50])
  NLopt.upper_bounds!(opt::NLopt.Opt, [50,50,50])
  # NLopt.local_optimizer!(opt, local_opt);
    const CONVERGE = [:SUCCESS, :FTOL_REACHED, :XTOL_REACHED, :STOPVAL_REACHED]
  (fval102, xb1, exitflag1) =
      NLopt.optimize(opt::NLopt.Opt, x0::AbstractVector)

```

F\_\_=3+(xb1[1]-1)^2+xb1[2]\*(xb1[3]+3)

---

<div class="post-metadata">

**Author:** ![Zhong\_Pan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhong_pan/32/19872_2.png) [@Zhong\_Pan](https://discourse.julialang.org/u/Zhong_Pan)\
**Post date:** [April 9, 2017, 6:01am UTC](https://discourse.julialang.org/t/nlopt-stogo-on-windows-doesnt-work/3080/6 "2017-04-09T06:01:01Z")

</div>

I was able to re-produce your issue. When :GD\_STOGO or :GD\_STOGO\_RAND are chosen as the algorithm the following error message is shown:

```julia
Error evaluating test_nlopt.jl
LoadError: ArgumentError: invalid NLopt arguments
while loading C:\temp\test_nlopt.jl, in expression starting on line 31
 in chk(::Int32) at NLopt.jl:259
 in chks(::Int32) at NLopt.jl:276
 in optimize!(::NLopt.Opt, ::Array{Float64,1}) at NLopt.jl:529
 in optimize(::NLopt.Opt, ::Array{Float64,1}) at NLopt.jl:532
 in include_string(::String, ::String) at loading.jl:441
 in include_string(::Module, ::String, ::String) at eval.jl:32
 in (::Atom.##59#62{String,String})() at eval.jl:81
 in withpath(::Atom.##59#62{String,String}, ::String) at utils.jl:30
 in withpath(::Function, ::String) at eval.jl:46
 in macro expansion at eval.jl:79 [inlined]
 in (::Atom.##58#61{Dict{String,Any}})() at task.jl:60

```

Choosing other algorithms seem to work fine.

Some online discussion says GD\_ algorithms require lower and upper bounds, and when they are missing the “invalid argument” error can appear. However, I see that you already provided the bounds.

Sorry I couldn’t find a solution for this problem.

---

<div class="post-metadata">

**Author:** ![flomenbom](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flomenbom](https://discourse.julialang.org/u/flomenbom)\
**Post date:** [April 9, 2017, 9:10am UTC](https://discourse.julialang.org/t/nlopt-stogo-on-windows-doesnt-work/3080/7 "2017-04-09T09:10:52Z")

</div>

thanks, the question is whether the julia c++ feature is broken  
rather than there is a mathematical error with juilia implementation of NLopt

for example all nlopt algorithms that work with BFGS algorithm  
do not succeed to present result (the result is: nlopt failure: -1)  
These are LD\_LBFGS , LD\_VAR2 etc

STOGO algorithm, also work with that BFGS algorithm  
yet here the error message is different  
implying that the problem is technical (perhaps the c++ implementation is broken )

in case you can check other C++ algorithm in julia  
verifying that the C++ feature working,  
that can help solving the problem  
\*\*\* that might help also others  
(i will also try to check simple c++ algorithm (function) in julia )

---

<div class="post-metadata">

**Author:** ![Zhong\_Pan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhong_pan/32/19872_2.png) [@Zhong\_Pan](https://discourse.julialang.org/u/Zhong_Pan)\
**Post date:** [April 9, 2017, 7:35pm UTC](https://discourse.julialang.org/t/nlopt-stogo-on-windows-doesnt-work/3080/8 "2017-04-09T19:35:49Z")

</div>

Sorry I am not familiar with these algorithms at all, so it will be too hard for me to debug the C++ code. Did you try contacting the authors of the C++ code and/or those who are familiar with the C++ NLopt library?

---

<div class="post-metadata">

**Author:** ![flomenbom](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@flomenbom](https://discourse.julialang.org/u/flomenbom)\
**Post date:** [April 10, 2017, 10:08am UTC](https://discourse.julialang.org/t/nlopt-stogo-on-windows-doesnt-work/3080/9 "2017-04-10T10:08:03Z")

</div>

i work to check the cpp package in julia  
and the cxx package in julia

[https://github.com/Keno/Cxx.jl](https://github.com/Keno/Cxx.jl)  
[https://github.com/timholy/Cpp.jl](https://github.com/timholy/Cpp.jl)

These are both with errors to solve  
The problem is probably with the c++ feature rather than julia nlopt implementation
