Chapter 4. Building Applications

Abstract

Sourcery VSIPL++ comes with example programs, installed in the share/sourceryvsipl++ subdirectory. This chapter explains how to compile, link, and run these programs. You can modify these programs to develop your own Sourcery VSIPL++ applications.

Table of Contents

4.1. Building Manually
4.2. Building with GNU Make
4.3. Building with Microsoft Visual Studio
4.4. Running Serial Applications
4.5. Running Parallel Applications
4.6. Building Applications with the VSIPL API

This chapter assumes that you have installed Sourcery VSIPL++ in /opt/sourceryvsipl++-2.2-9. If you have used a different path, you will have to adjust the filenames below accordingly. It is also assumed that the current directory is writable by you. For example, you can use your home directory or /tmp as the current directory. Finally, the examples in this chapter assume that you are using the GNU C++ compiler. If you are using another C++ compiler, you may have to make minor changes to the commands shown.

4.1. Building Manually

The file /opt/sourceryvsipl++-2.2-9/share/sourceryvsipl++/example1.cpp contains a very simple VSIPL++ program. You can use this file as a template for developing much more complex programs.

When building Sourcery VSIPL++ applications, you must ensure that your compiler can find the necessary header and library files. Since Sourcery VSIPL++ may depend on other libraries, the easiest way to determine the necessary compiler directives is with the pkg-config command.

Before pkg-config can find information about Sourcery VSIPL++, it is necessary to make sure that Sourcery VSIPL++'s lib/pkgconfig subdirectory is in pkg-config's search path. You can check the search path by examining the PKG_CONFIG_PATH environment variable. To set the path:

> export PKG_CONFIG_PATH=/opt/sourceryvsipl++-2.2-9/lib/pkgconfig

First, determine what compiler is recommended:

> CXX=`pkg-config vsipl++ --variable=cxx`

Second, to compile the program, use the following command:

> $CXX -c `pkg-config vsipl++ --cflags` \
                          `pkg-config vsipl++ --variable=cxxflags` \
      /opt/sourceryvsipl++-2.2-9/share/sourceryvsipl++/example1.cpp

Finally, to link the program, use the following command:

> $CXX -o example1 example1.o `pkg-config --libs vsipl++`

Now that you have built the example program, you can run it like any other program, with:

> ./example1

4.1.1. Using pkg-config

When building applications, it is important to use the same C++ compiler that was used to build the Sourcery VSIPL++ library. Different C++ compilers, even different versions of the same compiler, may have incompatible linking conventions or different standard library implementations. However, it is possible to determine the compiler used to build Sourcery VSIPL++ via pkg-config:

> pkg-config --variable=cxx vsipl++

Using this, the previous commands to compile and link the example program become:

> `pkg-config --variable=cxx vsipl++` \
          -c `pkg-config --cflags vsipl++`
	  /opt/sourceryvsipl++-2.2-9/share/sourceryvsipl++/example1.cpp
> `pkg-config --variable=cxx vsipl++` \
          -o example1 example1.o `pkg-config --libs vsipl++`

If pkg-config is not available on your system, you can specify the search paths manually. With most compilers, the -I switch can be used to specify directories containing header files. Use the following command to compile the program:

> g++ -c -I /opt/vsip/include \
      /opt/sourceryvsipl++-2.2-9/share/sourceryvsipl++/example1.cpp

To link the program manually, you must tell the compiler where to find the libraries when linking. For most compilers, the -L switch is used to specify directories to search for libraries, while the -l switch is used to specify the names of libraries to use. Use the following command to link the program:

> g++ -o example1 -L /opt/sourceryvsipl++-2.2-9/lib example1.o -l vsip

If Sourcery VSIPL++ was configured to use other libraries, such as MPI, it will be necessary to manually specify -L and -l options accordingly. These necessary options can be determined by looking in the /opt/sourceryvsipl++-2.2-9/lib/pkgconfig/vsipl++.pc file. It contains a line prefixed with "Libs:" which indicates the libraries necessary to link a Sourcery VSIPL++ program.