[SOLVED] Testbed(Linux): cannot find -lGLUT

I've already built Box2D and succesfully run HelloWorld. I'm using Box2D version 2.2.1 with premake 4.4 beta. I'm getting the following error when trying to compile:

Code:
david@David-MintDesktop ~/Documents/Box2D_v2.2.1/Build/gmake $ sudo make config=debug
==== Building Box2D (debug) ====
==== Building GLUI (debug) ====
==== Building HelloWorld (debug) ====
==== Building Testbed (debug) ====
Linking Testbed
/usr/bin/ld: cannot find -lGLUT
collect2: ld returned 1 exit status
make[1]: *** [bin/Debug/Testbed] Error 1
make: *** [Testbed] Error 2


I've found tons of things online about similar problems, but I haven't found a single one exactly like mine that provided a good solution. I imagine there's at least one out there, but I'm sorry I was unable to find it.

It seems the problem is with finding GLUT, which i'm guessing is specifically freeglut, but I actually don't know a whole lot about it. I tried installing a freeglut package from my package manager but that didn't solve it so I got rid of it. I also installed the packages that irresistable force suggested on his website (I love the Ron Paul videos btw!) and left them on just in case (I'm using Mint which uses Ubuntu repositories).

Finally, the last thing I tried was compiling the freeglut that came with the Box2D distribution. I successfully compiled a debug static library called libfreeglut_static.a.

I placed copies in /usr/local/lib/, ~/Documents/Box2D_v2.2.1/freeglut/, and ~/Documents/Box2D_v2.2.1/Build/gmake/, and the Testbed still gave the error whether I left the makefile's line as -lGLUT or -llibfreeglut_static.

Here is what that line that says -lGLUT looks like in Testbed.make:

Code:
  LIBS      += bin/Debug/libBox2D.a bin/Debug/libGLUI.a -lX11 -lGL -lGLU -lGLUT


Thanks to everyone in advance for their help, I really just want to build the Testbed so I can understand the physics a little before putting it into a game.
why not just use the cmake file to build everything together?
This might be useful: http://www.iforce2d.net/b2dtut/setup-linux
Thanks for the suggestion. However, CMake isn't working as cleanly as your site suggests. I think the directory structure has changed since the version you built. I had seen your site before and tried it, but it's just not working. I want to work on it a little bit more to see if I can get it built, but if not, then I'll post more specific questions after.
Alright, I've stayed up till 5am my local time so I'm going to bed. I just want to post where I've left off in case anyone can shed light on this while I'm asleep. Here is my process:

    1) I downloaded the latest Box2D (2.2.1) release to my Documents folder.
    2) I ran cmake-gui and set both the source code and binary folders to /home/david/Documents/Box2D_v2.2.1/. This is the root directory of the downloaded release where the top level CMake files are. If I changed the binary output directory, CMake would just copy everything in the release into its own /home/david/Documents/Box2D_v2.2.1/Build/ directory. I didn't really want this.
    3) I checked build-shared, build-examples, install, install-doc, and made the build type Debug and install-prefix /usr/local/. The last option simply copies the compiled library to /usr/local/lib/ which I would have done myself anyway so it was convenient.
    4) I clicked configure and then generate and chose Unix Makefile.
    5) In a terminal, I went to /home/david/Documents/Box2D_v2.2.1/ and ran sudo make. Below is the output:

Code:
david@David-MintDesktop ~/Documents/Box2D_v2.2.1 $ sudo make
[ 42%] Built target Box2D_shared
Linking CXX executable HelloWorld
/usr/bin/ld: cannot find -lBox2D
collect2: ld returned 1 exit status
make[2]: *** [HelloWorld/HelloWorld] Error 1
make[1]: *** [HelloWorld/CMakeFiles/HelloWorld.dir/all] Error 2
make: *** [all] Error 2


I created a symbolic link /usr/local/lib/Box2D pointing to /usr/local/lib/libBox2D.so.2.1.0 which was created by make in the hopes that the linker would pick it up. It still didn't.

So as you can see, CMake doesn't even get me as far as I got with premake4. At least with premake4 I could run HelloWorld. And as for iforce's site, there no longer is a /home/david/Box2D_v2.2.1/Box2D/Build/ directory. Build/ is now in the root directory. I pretty much translated your directions directly to the new structure, but now making HelloWorld cannot find Box2D.
Actually I've never tried building shared libs, maybe the cmake settings to install the lib are not right for your flavor of linux.
fwiw I just checked now and this works:
Code:
wget http://box2d.googlecode.com/files/Box2D_v2.2.1.zip
unzip Box2D_v2.2.1.zip
cd Box2D_v2.2.1/Build
cmake ..
make
Testbed/Testbed
This builds a static lib, in a 'shadow-folder' and doesn't install anything so it's not exactly what you're trying to get with your cmake gui settings, but if you really just want to build the Testbed so you can understand the physics a little before putting it into a game it should be ok. Note that there are a few pre-requisites which you can use yum or apt-get to install.
Wow, thank you very much! It was something fishy indeed... apparently the Makefile absolutely must be placed in the Build directory and made from there. Before Box2D, I had started building and using the latest dev snapshot of SFML. That also used CMake. When building SFML, I never needed any Build directory; I generated the Makefile in the SFML root directory and ran make successfully from there.

In the case of Box2D, there was a build directory, but I tried avoiding it because I didn't feel the need to duplicate the same root directory structure inside of Build. As it turns out, this is important for the build script to find the included freeglut. I didn't realize the issue until I followed your directions to the dot (literally, the 2 dots in cmake .., haha).

I still don't see why it couldn't just link to my distro's freeglut, even when I changed the Makefile to try and find it. Then again, that was under premake which I don't quite understand yet. From now on, when using CMake, I will definitely use the Build directories for any project, haha.

Thanks a million!
Just in case anyone else hits the "cannot find -lGLUT" error (in my case using 32-bit Ubuntu 'Precise'), one needs to do 2 things:
  • Ensure the freeglut3-dev package is installed (you might already have freeglut3 but that's only the runtime -- development needs the -dev package!)
  • Tweak the...
    Code:
    Build/gmake/Testbed.make
    ...file from...
    Code:
    -lGLUT
    ...to...
    Code:
    -lglut
    ...in 2 places.
Things should then proceed fine.
HTH, Rupert
p.s. I also needed to tweak the premake4.lua script to correct the spelling of Helloworld.cpp to HelloWorld.cpp but maybe this is just a test to see whether you're worthy of using the library 😉

Original thread: https://box2d.org/forum/viewtopic.php?t=8768