Skip to content

Compiling a library and using it in your project

devnoname120 edited this page Jan 25, 2017 · 2 revisions

This page explains how to compile and install an unsupported library so that you can use it in a Vita homebrew project. If the library that you are willing to use does not have too many dependencies, it should be pretty straightforward.

There exists multiple build systems, here is how to do it with the principal ones:

CMake

Files: CMakeLists.txt

We will use yaml-cpp for the example.

Let's open CMakeLists.txt in an editor. Under Project Options, there are two interesting lines:

option(YAML_CPP_BUILD_TOOLS "Enable testing and parse tools" ON)
option(YAML_CPP_BUILD_CONTRIB "Enable contrib stuff in library" ON)

We don't need these tools, and the less you build, the less it is likely to fail. So we will disable the two options when compiling the library.

Let's create a build folder and enter it:

mkdir build
cd build

Now it is time to prepare the build files:

cmake -DCMAKE_TOOLCHAIN_FILE=$VITASDK/share/vita.toolchain.cmake -DYAML_CPP_BUILD_TOOLS=OFF -DYAML_CPP_BUILD_CONTRIB=OFF ../

The first argument lets CMake know about the Vita compiler, and the two other options allow to disable the unneeded options that we saw above.

Now we can build the library:

make

And install it:

make install

The library is now installed, you can use it in your Vita projects.

GNU Autotools

Files: configure.ac, Makefile.am, configure

We will use Onigmo for the example.

First we tell the autoconfig tool that we want to compile the library for the PS Vita:

./configure --host arm-vita-eabi --disable-shared --enable-static

Now we can compile it:

make

And finally install it:

make install

You can now use this library in your Vita projects.

GNU Make

Files: Makefile

GNU Make is the basic building system, and most build systems actually produce a Makefile and execute this tool.

We will use JSMN for the example. Note that if you are looking for a JSON library in C, Jansson or cJSON is probably a better choice.

Let's open the file Makefile.

On the top of the file it is written that we need to set our build configuration here. Let's add some variables that tell about the various Vita compilation tools:

PREFIX  	= arm-vita-eabi
CC      	= $(PREFIX)-gcc
CFLAGS  	= -Wl,-q -Wall -O3 -Wno-unused-variable
ASFLAGS 	= $(CFLAGS)

Now save this file, close it, and run this:

make

The library is now compiled. Usually you would issue a make install to install the library to the vitasdk, but this particular library does not have an install recipe. We will install it manually:

cp libjsmn.a $VITASDK/arm-vita-eabi/lib/
cp jsmn.h $VITASDK/arm-vita-eabi/include/

You should now be able to use this library in your homebrew.

Clone this wiki locally