Cannot build Box2D on Linux: linker error
I’m trying to build Box2d v2.3.1 on my Ubuntu (13.10) machine. That’s what I’m doing :
$ premake4 gmake $ cd Build/gmake/ $ make
But the test bench was not built correctly. I get a lot of undefined reference errors for glfw and glew symbols like this:
obj/Debug/Testbed/Main.o: In function `main': /home/mostafa/.adobe/box2d-2.3.1/Box2D/Build/gmake/.. /.. /Testbed/Framework/Main.cpp:458: undefined reference to `glfwCreateWindow'
I installed the development kits for GLFW and GLEW. I also checked the Testbed.make makefile, and since I don’t see a reference to glfw, add -lglfw to the two places where the LIBS variable is defined. But I’m still getting the same error.
After a lot of searching and tweaking, I finally managed to solve this problem. That’s what I did:
Make sure you have the latest version of Premake. I have to install premake 4.4 (beta).
Compile and install the latest version of GLFW (currently 3.0.4) from source. The version in the Ubuntu repository does not work.
Make sure you have the GLEW and XRG development kits. I installed these from the Ubuntu repository:
sudo apt-get install libglew-dev xorg-dev
premake4gmake in the Box2D directory, go to
Build/gmakeand edit Testbed.make. Change the LIBS += $(LDDEPS) -lX11 -lGL -lGLU -lglut line to this
LIBS += $(LDDEPS)-lX11 –
lGL -lGLU -lglut -lGLEW -lglfw3 - lX11 -lXxf86vm -lpthread -lXrandr -lXi