Linking to the SNOPT Library¶
The compiled SNOPT libraries are named libsnopt7
or
libsnopt7_cpp
. The Fortran and C subroutines (if enabled) of SNOPT are
contained in libsnopt7
, while the library libsnopt7_cpp
contains
Fortran, C, and C++ subroutines. If you need C++ support, you must link to
libsnopt7_cpp
with a C++ compiler, regardless of language used.
An example of how to compile and link a Fortran example with the SNOPT library:
>> gfortran -O -c myProb.f -o myProb.o
>> gfortran -O myProb.o -o myProb -L$SNOPT/lib -lsnopt7
A Fortran example linking to the C++ library of SNOPT:
>> gfortran -O -c myProb.f -o myProb.o
>> g++ -O myProb.o -o myProb -L$SNOPT/lib -lsnopt7_cpp
A C++ example linking to the C++ library of SNOPT:
>> g++ -O -I$SNOPT/include -c myProb.cpp -o myProb.o
>> g++ -O myProb.o -o myProb -L$SNOPT/lib -lsnopt7_cpp
Note
If utilizing shared libraries (.dylib/.so), the location of the
library files must be added to DYLD_LIBRARY_PATH
on macOS or
LD_LIBRARY_PATH
on Linux.
Matlab Setup¶
To use SNOPT in the Matlab environment, identify the appropriate Matlab mex-file extension for your machine.
Linux: .mexa64
macOS: .mexmaci64
Windows 64-bit Matlab: .mexw64
Windows 32-bit Matlab: .mexa32
The location of the mex-file and the assocated Matlab m-files must be added to the Matlab path. There are 2 ways to do this:
use the
setpath
command at the Matlab terminal, orgo to
Home -> Environment -> Set Path
and add the location there.
See also
To compile the Matlab mex-file from source, see Compiling for Matlab.
License Setup¶
Before using the optimization libraries, you must set the environment
variable <software name>_LICENSE
, where <software name>
is either
“SNOPT” or “SQOPT”, to point to the license file, e.g.,
export SNOPT_LICENSE=$HOME/licenses/snopt7.lic % at the terminal
set SNOPT_LICENSE "C:\Users\me\snopt7.lic" % at the Windows command line terminal
setenv('SNOPT_LICENSE','/Users/me/licenses/snopt7.lic') % in matlab
Windows¶
On Windows systems, you need to have both the
.dll
file and the.lib
file. The location of the library files (.lib
and.dll
) must be added to the system path. If you have admin privileges, then you can modify the path to add the location. Otherwise, place the library files in the same location as your calling executable.Depending on your system, you may need to download and install some additional libraries from Microsoft and/or Intel. See our FAQ entry.
If the Windows SNOPT libraries are compiled as DLLs, you must also compile your programs with the
/MD
switch.