Compilation is only necessary if are building SNOPT from source. If you are using compiled libraries or Matlab, see Linking to the SNOPT Library.
The simplest commands to compile and install the optimization package from source code are
>> ./configure >> make >> make install
make install will install the libraries and header files. By default,
the libraries are installed into
$SNOPT/lib and header files are
$SNOPT is the location of the
software package. The command
>> make examples
will compile the included examples in the directory
The following command will compile AND execute the examples, and check for
>> make check
Change the location of the installed libraries and header files. For example,
./configure --prefix=$HOMEwill install the libraries into
$HOME/liband header files into
$HOME/include. By default, the libraries and header files are installed into $SNOPT/lib and $SNOPT/include.
Compile with debug flags
Compile the library with 32-bit or 64-bit integers.
Use this flag to set the path to your Matlab installation if you want to compile Matlab mex-files.
Enable (or disable) C support for SNOPT. The C interface will be compiled into the SNOPT library
libsnopt7. C support is enabled by default.
Enable (or disable) C++ support for SNOPT. Resulting SNOPT library is called
Compile with AMPL support; the AMPL library and binaries will be compiled if
--with-amplis used. The user can also provide the location of an external AMPL library. The configure script will search for
Provide a BLAS library. For example,
--with-blas="-L/usr/local/lib -lblas. If Matlab support is enabled and you wish to compile the Matlab mexfile with the Matlab-provided blas library, use
Generate position-independent code (PIC). May be necessary on Linux systems.
Compiling for Matlab¶
Matlab only supports certain Fortran compilers for mex-file compilation. Please check Mathworks documentation to determine which compiler is needed (see www.mathworks.com/support/compilers.html).
Precompiled mex-files are also provided with the SNOPT package that allow the user to call the nonlinear and quadratic solvers in each package from Matlab. These files are available for 64-bit machines running Mac OSX, Windows or Linux. (See Compiling in Windows for info on Windows systems.)
To compile a Matlab mex-file, configure the optimization package with the Matlab option with the following command:
>> ./configure --with-matlab=/path/to/Matlab -with-64
where the path to Matlab is specified.
On a Linux machine, the user must also configure with
>> ./configure --with-matlab=/path/to/Matlab --with-64 --with-pic
The 64-bit integer tag is required because Matlab only supports 64-bit integers.
By default, the mex-files will be compiled using SNOPT’s BLAS
subroutines. To compile against Matlab’s BLAS library, use
After successful configuration, type the following command to make the mex-file
>> make matlab
A new Matlab mex-file will be compiled and placed in the matlab directory of the optimization package.
Compiling with C/C++¶
By default, support for C interoperability is enabled. Because C++ interoperability requires the use of a C++ compiler to link executables and libraries, C++ support is disabled by default. To enable or disable language support, compile SNOPT with the following options
>> ./configure --without-c % disable C support >> ./configure --with-cpp % enable C++ support
The main SNOPT library is
libsnopt7 and contains the Fortran and
(optionally) the C interface. When C++ support is enabled, an additional
libsnopt7_cpp is also built, supporting all three languages. A
C++ compiler must be used when linking to
libsnopt7_cpp, regardless of
your program language.
Compiling in Windows¶
Makefiles (nmakefile.win, nmakefile_interface.win, nmakefile_matlab.win) are
included in the directory
$SNOPT/win64 and are intended to be used with
NMAKE and the Command Prompt with Intel Compilers (32-bit or 64-bit).
Compile the DLL Fortran/C/C++ SNOPT library.
Compile SNOPT/SQOPT matlab mexfiles.
To see the commands available:
>> nmake -f <makefile name> help
Please note that these Windows Makefiles do not have the same functionality as the ones for Linux/Unix systems. They may require some modifications by the user. In particular, the user should make sure that the variables in the makefiles point to the correct locations.
By default, the files assume that the SNOPT directory structure has not been altered and that you will run the nmake commands listed below in this directory. Matlab mex-file compilation If you have more than one version of Matlab installed, then you may want to modify the MEX variable in nmakefile_matlab.win to point to the appropriate location.
Additionally, Matlab’s configuration assumes that all Fortran files are in
fixed format. To get around this, nmakefile_matlab.win uses the additional
intel_fortran_**_vs20**.xml. This is a copy of a file from
Matlab (usually found in
Files\MATLAB\r20**\bin\mexopts). Note the ones included in the SNOPT
distribution are configured for Visual Studio 2017.