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.
-
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