I managed to fix this at last, after lots of searching and tweaking. This is what I did:
Make sure you have the very latest version of premake. I had to install premake 4.4 (beta version).
Compile and install the latest version of glfw (3.0.4 at the moment) from source. The version in Ubuntu's repositories does not work.
Make sure you have glew and xorg development packages. I installed these from Ubuntu's repository:
sudo apt-get install libglew-dev xorg-dev
After running
premake4 gmake
in Box2D directory, go toBuild/gmake
and edit Testbed.make. Change the lineLIBS += $(LDDEPS) -lX11 -lGL -lGLU -lglut
into thisLIBS += $(LDDEPS) -lX11 -lGL -lGLU -lglut -lGLEW -lglfw3 -lX11 -lXxf86vm -lpthread -lXrandr -lXi
.Now run
make
.