Step 4: Link your code to NOX

Using the Export Makefile System

NOX and LOCA support the export makefile system to streamline issues dealing with linking against user applications. When NOX and LOCA are installed using the "make install" command, it will install two Makefiles that contain all flags needed to link an application against the solvers. The first Makefile is Makefile.export.nox. The important flags are NOX_INCLUDES, NOX_LIBS, LOCA_INCLUDES, and LOCA_LIBS. These make variables contain all paths and libraries needed to link against NOX and LOCA.

The second makefile is Makefile.export.nox.macros. This file contains all the flags and compiler options that the Trilinos libraries were built with. One challenge in linking applications against Trilinos is using a consistent set of compiler flags. This file take all the guesswork out of the process. Just include this file in your own makefile and use the associated flags.

Below is an example of a Makefile a user can write to link against NOX. This example can be found in the directory Trilinos/packages/nox/examples/lapack/NOX_ExportMakefile. In this example the user has written an interface to the nox lapack support for soving the Rosenbrock exmaple. The code is found in the file Rosenbrock.C. The file Makefile includes the NOX export makefiles:

#####################################################################
## Example Makefile for a user application that does not use autoconf
## - Uses lapack concrete instations for group and vector 
## - Must use gnu-make (gmake) if the "shell" command is invoked
#####################################################################

##
## Set the Trilinos install directory 
##
TRILINOS_INSTALL_DIR = /home/rppawlo/trilinos_local

##
## Include any direct Trilinos library dependencies - in this case only nox
##
include $(TRILINOS_INSTALL_DIR)/include/Makefile.export.nox.macros
include $(TRILINOS_INSTALL_DIR)/include/Makefile.export.nox

##
## Use one of the following lines (2nd line is for non-gnumake platforms)
##
COMPILE_FLAGS = $(shell perl $(TRILINOS_INSTALL_DIR)/include/strip_dup_incl_paths.pl $(NOX_CXXFLAGS) $(NOX_DEFS) $(NOX_CPPFLAGS) $(NOX_INCLUDES))

#COMPILE_FLAGS = $(NOX_CXXFLAGS) $(NOX_DEFS) $(NOX_CPPFLAGS) $(NOX_INCLUDES)

##
## Use one of the following lines (2nd line is for non-gnumake platforms)
##
LINK_FLAGS = $(shell perl $(TRILINOS_INSTALL_DIR)/include/strip_dup_libs.pl $(NOX_LIBS))

#LINK_FLAGS = $(NOX_LIBS)

##
## Build your application code
##

Rosenbrock.exe: Rosenbrock.o
    $(NOX_CXXLD) $(NOX_CXXFLAGS) -o Rosenbrock.exe Rosenbrock.o $(LINK_FLAGS)

Rosenbrock.o:
    $(NOX_CXX) $(COMPILE_FLAGS) -c Rosenbrock.C

clean:
    rm -f *.o Rosenbrock.exe *~

In this example, we assume the user has installed Trilinos into the directory /home/rppawlo/trilinos_local. This directory is specified when configuring Trilinos with the --prefix=/home/rppawlo/trilinos_local.

The first thing a user does is include the two export makefiles generated by nox. Next, the compile and link flags are defined. Note that there exist 2 ways of defining the COMPILE_FLAGS and LINK_FLAGS. One is for users that use gnu's version of make and the second (commented out) is for non-gnumake users. The shell command is only supported in gnumake and is used to strip out duplicate headers. The export makefile system has the unfortuante side effect of generating duplicate include paths when being installed. Finally, the user's application uses the compile and link flags to build their own executable.

Compiling Without using Export Makefiles

Although we don't recommend it, users can link NOX and LOCA to their application without using the export makefile system. To compile your code in this manner, your Makefile should look something like the following, assuming NOX was installed in /usr/local.

NOX_PREFIX = /usr/local
LDFLAGS = -L$(NOX_PREFIX)/lib 
LIBS = -lnox
CXXFLAGS = -I$(NOX_PREFIX)/include/

Compiling with LAPACK support:

NOX_PREFIX = /usr/local
LDFLAGS = -L$(NOX_PREFIX)/lib 
LIBS = -lnox -lnoxlapack -llapack -lblas 
CXXFLAGS = -I$(NOX_PREFIX)/include/

Compiling with Epetra support:

We assume that Epetra, Aztec, and Ifpack are installed in the same place as NOX.

NOX_PREFIX = /usr/local
LDFLAGS = -L$(NOX_PREFIX)/lib 
LIBS = -lnox -lnoxepetra -laztecoo -lifpack -lepetra  -llapack -lblas 
CXXFLAGS = -I$(NOX_PREFIX)/include/

Note:
If compiling without using the export makefile system, you have to be very careful about which libraries are needed to link against. Enabling configure options typically brings in new library requirements. The export makefile system catches this automatically. Not using expor tmakefiles means YOU will have to catch the additional dependencies.

If you have problems...

If you have problems linking NOX and/or LOCA, please report them using Bugzilla; see Reporting Bugs and Making Enhancement Requests for more information.
Generated on Wed May 12 21:26:21 2010 for NOX by  doxygen 1.4.7