Thursday, May 15, 2014

Building Box2D on Linux

I wanted to build Box2D v2.3.1 on my Ubuntu 14.04 machine. It took me a lot of tweaking to do it, so I thought I'd document the process here.

First I tried the instructions I found here but I got these error messages:

CMake Error at CMakeLists.txt:29 (add_subdirectory):
  add_subdirectory given source "freeglut" which is not an existing
  directory.

CMake Error at CMakeLists.txt:30 (add_subdirectory):
  add_subdirectory given source "glui" which is not an existing directory.

-- Configuring incomplete, errors occurred!
I searched a bit and found out that cmake is no longer supported on Box2D I had to use premake. I ran "premake gmake" in Box2D directory, but I got:

No Premake script found!
Okay. This was easy to fix. I needed premake4, not the older version in Ubuntu's repositories. I installed the latest stable version of premake from premake website. This time, running "premake4 gmake" got me this:

/path/to/box2d-2.3.1/Box2D/premake4.lua:26: attempt to call global 'vpaths' (a nil value)
A bit more searching, and I found out I need the latest version of premake, that is the beta version. All right I got premake4.4 (beta) and this time it ran successfully. I switched to Build/gmake directory and ran "make".

At first things seemed to be going smoothly until I got lots of errors regarding undefined symbols belonging to glfw and glew. But I had the development packages for both of those installed. A lot of poking around and I managed to fix it at last. This is what I did.

  1. Compile and install the latest version of glfw (3.0.4) from source.
  2. Change this line in Build/gmake/Testbed.make:

    LIBS      += $(LDDEPS) -lX11 -lGL -lGLU -lglut

    into this:

      LIBS      += $(LDDEPS) -lX11 -lGL -lGLU -lglut -lGLEW -lglfw3 -lX11 -lXxf86vm -lpthread -lXrandr -lXi
And now, at last everything compiled correctly.

Tuesday, May 6, 2014

Transparently proxifying certain machines in the network

I use an Ubuntu box as a wifi access point/router in my home network. I wanted to transparently proxify certain machines on the network (mainly my Kindle paperwhite --long story!). I finally managed to do it like this:

sudo iptables -t nat -A PREROUTING -m mac --mac-source "MAC-ADDRESS" -p tcp --dport 80 -j REDIRECT --to-port 33128
 In which MAC-ADDRESS is the mac address of the machine I want to proxify. A squid instance is listening on 33128. I had to change this line in my squid configuration:

http_port 33128
to this:

http_port 33128 transparent
so that squid handles transparent proxy-ing correctly.

I'm using iptables version 1.4.21 on Ubuntu 14.04, and squid version 2.7.