# Compiling SNOPT¶

Note

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 installed into $SNOPT/include, where $SNOPT is the location of the software package. The command >> make examples  will compile the included examples in the directory $SNOPT/examples. The following command will compile AND execute the examples, and check for correct output

>> make check


## Configuration Options¶

• --prefix=/path/to/directory

Change the location of the installed libraries and header files. For example, ./configure --prefix=$HOME will install the libraries into $HOME/lib and header files into $HOME/include. By default, the libraries and header files are installed into$SNOPT/lib and $SNOPT/include. • --with-debug Compile with debug flags • --with-32, --with-64 Compile the library with 32-bit or 64-bit integers. • --with-matlab=/path/to/matlab Use this flag to set the path to your Matlab installation if you want to compile Matlab mex-files. • --with-c, --without-c Enable (or disable) C support for SNOPT. The C interface will be compiled into the SNOPT library libsnopt7. C support is enabled by default. • --with-cpp, --without-cpp Enable (or disable) C++ support for SNOPT. Resulting SNOPT library is called libsnopt7_cpp. • --with-ampl Compile with AMPL support; the AMPL library and binaries will be compiled if --with-ampl is used. The user can also provide the location of an external AMPL library. The configure script will search for amplsolver.a in /path/to/AMPL/. • --with-blas=<blas> Provide a BLAS library. For example, --with-blas="-framework Accelerate" or --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 --with-blas=matlab. • --with-pic 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 --with-pic. >> ./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 --with-blas=matlab. 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 library 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).

File name

Use

nmakefile_dll.win

Compile the DLL Fortran/C/C++ SNOPT library.

nmakefile_matlab.win

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 file intel_fortran_**_vs20**.xml. This is a copy of a file from Matlab (usually found in C:\Program Files\MATLAB\r20**\bin\mexopts). Note the ones included in the SNOPT distribution are configured for Visual Studio 2017.