How to add cell sdk libraries
In a previous post I explained how to create a library for a PPU program. In this post I am going to explain how to add cell sdk libraries. In this example I am showing how to use the spu simdmath library.
Imagine you are developing a SPU program and you need to use the fabsf4 function (see C/C++ Language Extensions for Cell Broadband Engine Architecture) to compute the absolute value of the elements of a vector.
The fasf4 function is contained in the simdmath library, so it is needed to include some headers and add some directories in the library search path.
In linux there are two types of libraries: static and dynamic libraries. Dynamic libraries in linux are the same as dll’s in Windows. In linux, dynamic libraries use to have ‘.so’ extension and static libraries ‘.a’ extension.
In this case we are looking for static libraries to include that code inside our binaries.
We have to find out the location of this library. The easiest way to find out where headers and libraries are is to perform a search.
[jsanchez@localhost opt]$ cd /opt
[jsanchez@localhost opt]$ find -iname ‘*simdmath.*’
./cell/sysroot/usr/lib/libsimdmath.so.3.0.3
./cell/sysroot/usr/lib/libsimdmath.so
./cell/sysroot/usr/lib/libsimdmath.a
./cell/sysroot/usr/lib/libsimdmath.so.3
./cell/sysroot/usr/lib64/libsimdmath.so.3.0.3
./cell/sysroot/usr/lib64/libsimdmath.so
./cell/sysroot/usr/lib64/libsimdmath.a
./cell/sysroot/usr/lib64/libsimdmath.so.3
./cell/sysroot/usr/spu/lib/libsimdmath.a
./cell/sysroot/usr/spu/include/simdmath.h
./cell/sysroot/usr/include/simdmath.h
[jsanchez@localhost opt]$
If you haven’t understood the find sentence, launch a terminal and put ‘man find’ for more information.
Now we have to include the library in the spu project. The useful data we have extracted from the previous sentece is the following:
/opt/cell/sysroot/usr/spu/include/simdmath.h (header)
/opt/cell/sysroot/usr/spu/lib/libsimdmath.a (library)
We then include the library reference as explained in a previous post using this information. There is just one exception, when the name of the library is added we have to put ’simdmath’, not ‘libsimdmath’, because of the eclipse plugin add the lib prefix when linking the program.
In the test program I added the following headers in the source code.
#include “simdmath.h”
#include “fabsf4.h”
My first foo library
Sometimes we develop a code we would like to be placed in libraries. The Cell BE IDE provides the ability of creating libraries, for both PPU and SPU. In this post I will show you the necessary steps to create a PPU library and link it into a PPU program.
The first step is to create a PPU library, so launch eclipse ide and do the following.
On the left panel where projects are shown right click and then select -> New -> Managed Make C++ Project. Fill the name and the place for the project to be stored and click next. The next dialog will ask you the project type, the Cell PPU Static Library entry has to be selected. Click finish.
We have created the PPU static library project, so we can place code. New->Class. We create a class called Foo with a simple public method to be called from our ppu project. I paste the code in the following lines:
Header
#ifndef FOO_H_
#define FOO_H_
class Foo
{
public:
Foo();
virtual ~Foo();
public : int Sum (int a, int b);
}; #endif /*FOO_H_*/
Body
#include “Foo.h”
Foo::Foo()
{
}
Foo::~Foo()
{
}
int Foo::Sum (int a, int b)
{
return a + b;
}
The next step is to create the PPU project. File-> New -> Managed Make C++ Project. Fill the name of the new project, the place to be located in, etc.
As the Cell BE Tutorial says we must add the libspe2 library to our project, so in the project options, C/C++ Build, configuration Settings, PPU GNU 32 bit C++ Linker-> Libraries->Libraries (-l) -> Add add(spe2)
Create a new source file: File -> New -> Source file (name.cpp) and write the following
#include “Foo.h”
int main(void)
{
return 0;
}
As we save the file and the compilation begins, it will return an error: ‘Foo.h no such file or directory‘. So we have to add extra information to the project to get this code found. We have to tell the project where to find header files as shown bellow.
Now we can place the rest of the code:
#include “Foo.h”
int main(void)
{
Foo f;
int res = f.Sum(2,3);
return 0;
}
The above code compiles fine but we get a linker error because we haven’t told the linker where the code is, so we add this information as shown bellow.

Finally we have our ppu library and a project that uses this library.
We can also a new spu library and use it from a spu projects. The mechanism is very similar the one I have tried to show you.
In my applications I use static libraries instead of dynamic ones. I am doing it because I am running the applications under the simulator and if I don’t do things this way my applications would fail unless I syncronize my simulated environment with the dynamic libraries.
Eclipse IDE for Cell Broadband Engine SDK
First step consist in installing Java JDK 1.4. Once Java is installed the enviorment variables JAVA_HOME and Path have to point to the jre directory.
For example: JAVA_HOME=/usr/java/j2sdk1.4.2_13/jre
PATH=$PATH:/$JAVA_HOME/bin
We can edit this lines in ~/.bash_profile .There are many ways of modifying/creating these variables, like editing /etc/profile, ~/.bashrc if we launch eclipse from a terminal, etc.
Next step is installing eclipse 3.2.x, CDT 3.1. In order to install the ide plugin for eclipse move to the eclipse menu:
Help -> Software Updates -> Find and install -> New local site ( /opt/cell/ide ), and then select ‘com.ibm.celldt.update‘.
-
Archives
- May 2009 (1)
- January 2009 (1)
- September 2008 (1)
- August 2008 (1)
- July 2008 (1)
- June 2008 (1)
- March 2008 (1)
- February 2008 (5)
-
Categories
-
RSS
Entries RSS
Comments RSS

