Skip to content

Instantly share code, notes, and snippets.

@gubatron
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gubatron/dc0e29b9273741c9c14c to your computer and use it in GitHub Desktop.
Save gubatron/dc0e29b9273741c9c14c to your computer and use it in GitHub Desktop.
How to build jlibtorrent for MacOSX
  1. Make sure g++ points to clang++

  2. Download the latest boost library (this works for Boost 1.56)

  3. If you look at build/build_macosx.sh in frostwire-jlibtorrent, you will see a few lines commented. They are steps that should be taken only once, we're taking those now.

Set the following environment variables.

$BOOST_ROOT <- The source folder from the boost libraries you downloaded.

$LIBTORRENT_ROOT <- Libtorrent's source folder.

Then execute this before we start building.

export CXXFLAGS="-stdlib=libc++ -std=c++11 -O3 -I$BOOST_ROOT"

JDK include paths.

Execute /usr/libexec/java_home -V to see where your JDK includes are. You will see something like

$  /usr/libexec/java_home -V
Matching Java Virtual Machines (8):
    1.8.0_20, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home
    1.8.0_11, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home
    1.7.0_13, x86_64:	"Java SE 7"	/Library/Java/JavaVirtualMachines/jdk1.7.0_13.jdk/Contents/Home
    1.7.0_13, x86_64:	"Java SE 7"	/Library/Java/JavaVirtualMachines/jdk1.7_current/Contents/Home
    1.7.0_10, x86_64:	"Java SE 7"	/Library/Java/JavaVirtualMachines/jdk1.7.0_10.jdk/Contents/Home
    1.7.0_06, x86_64:	"Java SE 7"	/Library/Java/JavaVirtualMachines/jdk1.7.0_06.jdk/Contents/Home
    1.6.0_65-b14-462, x86_64:	"Java SE 6"	/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-462, i386:	"Java SE 6"	/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

For macosx we'll pick that latest 64bit one, and we'll have 2 env variables to set

$JDK_INCLUDE_1 <- /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home/include
$JDK_INCLUDE_2 <- /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home/include/darwin

$LIBTORRENT_LIBS

This is the folder where we'll save all the libraries we'll be compiling, so that we can then create a single libjlibtorrent.dylib file. You want this folder to be outside of your frostwire-jlibtorrent so you don't mess things up or end up uploading binaries to the repo.

Build Boost

Go to BOOST_ROOT and execute $BOOST_ROOT/b2 variant=release link=static --stagedir=macosx stage

Build LibTorrent

Go to LIBTORRENT_ROOT and execute $BOOST_ROOT/bjam toolset=darwin variant=release link=static deprecated-functions=off

Copy the BOOST and LIBTORRRENT Libraries to $LIBTORRENT_LIBS

This we'll only do once, the libraries you want are the following:

$ ls -l
total 240320
-rw-r--r--  1 gubatron  macports     384824 Oct 15 17:13 libboost_chrono.a
-rw-r--r--  1 gubatron  macports     520008 Oct 15 17:13 libboost_date_time.a
-rw-r--r--  1 gubatron  macports     123648 Oct 15 17:13 libboost_system.a
-rw-r--r--  1 gubatron  macports    1074456 Oct 15 17:13 libboost_thread.a
-rw-r--r--  1 gubatron  macports  120933864 Oct 15 17:12 libtorrent.a

This is what you will do everytime you modify libtorrent.i

Go to frostwire-jlibtorrent root folder, and execute:

./build/run_swig.sh This will generate the libtorrent_jni.cpp which can be commit and pushed to be used later by the different ./build/build_xxx.sh scripts.

./build/build_macosx.sh (which should have hints to all this commented out)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment