Linux (Ubuntu) Intalling Problems and Guide !!

Hey
I was having major problems in getting Box2D to work. (Fixed them ... Just here to tell the tale )

This is what I had done -
I had initially downloaded the version 2.01 file available via SourceForge and tried to "make" it. Upon which I got an error that a certain memcopy function was not declared !! So I added the necessary header files in all the required files and again tried to "make" it. Then I got some other errors .. turns out I don't have GLUI and GLUT installed (Why do I need them .. I don't want the test bed! I just want the library ...)

So I installed those as well and retried. It compiled successfully, but there was not .a file in the library folder nor was there any HelloWorld example executable. And searching for some time I found this building page in the wiki which said I had to download a separate version for Linuxhttp://www.box2d.org/forum/download/file.php?id=365. (Basically I had been racking my brain for nothing !!)

Would it really be that bad to include a simple line in the readme "NOT FOR LINUX USERS - GOTO THIS PAGE ..." ? And If it's not meant for Linux users why in the world are there Makefiles. As far as I know (I could be wrong) they only work on Linux machines under normal circumstances.

Anyway after that I downloaded the "right" file and did the whole cmake and make thing. This time the .a file wasn't in the Library folder but it was in the Sources folder( Atleast it was there !! 🙂 ). After that I tried the next normal thing to do "make install" but that obviously didn't work (I mean why should such a basic thing be there !!)

Anyway then I tried compiling the basic HelloWorld program on my own and I got some "Missing Headers" file. Guess I had to manually add the location of the header files and the library during compilation. And then it finally worked !!

Now this isn't the normal was of compiling programs in Linux once we are done compiling the program usually we just do a "make install" and the files are sent to the appropriate place. Then during compilation we can just add a simple -lBox2D to the compiler settings and use a #include <Box2D.h> (Not "Box2D.h") and the library usually works fine.
In order to add that functionality I had to manually copy the "libBox2D.a" file in the /usr/lib/ folder and then move both the Box2D.h and the Sources folder to the /usr/include/ directory and manually edit the Box2D.h file to remove all the "../".
Examples ;-
This -------- #include "../Source/Common/b2Settings.h"
To ---------- #include "Source/Common/b2Settings.h"

And now all I have to do is add the -lBox2d.a to the compiler options and I'm done !!

Hope this helps people .. (This entire Process really frustrated me !!)

PS : Was just adding the link given in the wiki and I found this page :- http://www.box2d.org/wiki/index.php?tit ... with_Linux ... damn !! (Why did I not see that earlier !!)
Seems there's quite a lot of different problems you ran into there, sorry. Ideally, I'd like to see them all fixed so future users do not have to go through the same. But as I understood make, you cannot have just one makefile that covers all cases, hence why there are build automation programs (and project files included with Box2D).

I'm not an expert in this and I don't run linux, and I use an IDE, but I'll attempt to address your issues, because I have more time on my hands than those more qualified.

certain memcopy function was not declared

This sounds like a fixable portability mistake. What was going wrong, where, and how did you fix it?

I don't want the test bed! I just want the library

Looks like the root makefile makes everything. There is a make in Source that compiles just what you want. This could do with better labelling, perhaps?

So I installed those as well and retried. It compiled successfully, but there was not .a file in the library folder nor was there any HelloWorld example executable

It seems these should have been created. It seems everything is created in /somefolder/Gen/float/, did you try those?

I had to download a separate version for Linux

Yes, in order to use CMake, which is not the same thing as make at all. And I cannot speak for how well or badly that extra version works, someone just shoved it on the wiki.

And If it's not meant for Linux users why in the world are there Makefiles

Pendantically speaking, makefiles can be read by several platforms. But yes, for all real purposes, those makefiles are provided for Linux compilation, and I would have presumed them to work.

"make install" but that obviously didn't work

Not sure what this is meant to do, but there doesn't seem to be anything to install, as Box2D is not a program.

Anyway then I tried compiling the basic HelloWorld program on my own and I got some "Missing Headers" file. Guess I had to manually add the location of the header files and the library during compilation

Yes, let's all avoid manually compiling stuff.

Now this isn't the normal was of compiling programs in Linux once we are done compiling the program usually we just do a "make install" and the files are sent to the appropriate place. Then during compilation we can just add a simple -lBox2D to the compiler settings and use a #include <Box2D.h> (Not "Box2D.h") and the library usually works fine.

Ah, ok, I see about make install now. Box2D is not set up to do this, and it evidently should be.

PS : Was just adding the link given in the wiki and I found this page :- http://www.box2d.org/wiki/index.php?tit ... with_Linux ... damn !! (Why did I not see that earlier !!)

That helps you build .so libraries, but I think you would still have the rest of your problems here.


So in summary, it seems to me there are the following real problems:
  • Code does not compile on your linux platform
  • Compilation output locations differs from expectation
  • No make install command.
  • Wiki/readme needs to be clear about make as an option for building.


If you would let me know what you did to fix (1) (with memcopy), I'd be happy to update the source. (2) and (3) will take some genuine thought and work (respectively), so I suppose they are best off going on the TODOLIST. I notice that "CMake" is already on there, for v2.2, which will likely fix these complaints. I can do (4) once we've finished discussing the matter at hand (there's little point if it is necessary to change things).
I agree with BorisTheBrave's assessment. I can add a couple of things: the makefiles included are for Linux systems and were developed (I wrote them) and work properly on my Fedora 6 system. I used the stock standard gnu makefile system for these makefiles. They generate both fixed and floating point versions of the library and the testbed. They will also generate NDS compatible libraries. They will only generate .a library files, not .so shared libraries. If there is any interest, adding .so libraries would be pretty easy. Because only the .a version of the library is generated, there is no reason to "install" these files as you can -I include the source tree of the library for your compiles and link in the .a library in your gcc compile line.

If the .so library file approach is taken then you would have to include the library with the executable distribution and would have to install it into someplace that the executable would find it.
For fixing the missing header files I just added
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

in the file Commons/b2Settings.h. Since that file is used almost everywhere it fixes the problem and saves us the trouble of adding those headers to multiple files.

The compilation produces the .a file in the Sources directory which is not really a big problem (but I guess it should be fixed .. I know nothing about cmake .. )

The part about "make install" can easily be automated using a script (I guess I could write it ..how hard could it be ?). I don't think it would be possible (I really don't know .. just a hunch) to create a make install command as -
1. The Makefile is automatically generated using the cmake command.
2. Copying the libBox2D.a file to the /usr/lib/ directory is fairly simple but there are some problems with the Box2D.h file. Firstly it needs to be modified, secondly it access the Source code header files which again need to be copied.

In case anyone know adequate amount of shell scripting this is what need to be done :-
1. Copy libBox2D.a to /usr/lib/ or /usr/local/lib
2. Create a new folder by the name of Box2D in the /usr/bin or /usr/local/bin directory.
3. Copy all the header files from the source code and the "Box2D.h" file to that folder.
4. Edit the Box2d.h file to remove everything before b2 in each include.
Eg :-
This ---- #include "../Source/Common/b2Settings.h"
To ---- #include "b2Settings.h"
(This is main step which I don't know how to do - I could write a C++ program or python script for it, but I have no idea how to do this via shell scripting)

And then tell all the Linux users to use
#include <Box2D/Box2D.h> instead of
#include <Box2D.h> or "Box2D.h".

(I prefer making a different folder for Box2d and not cluttering up the lib dir with a sources folder)

----------------------------------------------

About the wiki - The download page should indicate that there are different versions for Linux and Windows or it could include a simple 10 sec redirect page saying Linux users please click here and Windows user forget about this page and wait for 10sec !!

@ kavaler -
Yes it would be really simple to add -L(Directory Path) to the compiler, but the question is about conforming to the standard.

Linux and Windows OS are different and there are different things one expects from both these operating systems.
In a Linux operating system I would impulsively think of adding (as would many other linux users) a -l(lib name) and not bother about the -L as it is the norm for all lib files to be placed in /usr/lib/ directory.
Whereas in windows I would always manually add the search path.

We should conform to the usual standard. It's easier.
You can try this makefile and adapt it as you see fit. It replaces the makefile in Source. Try make install.
Hi everyone !

I have been trying to get started with box2D in Linux and am not being able to do so. It seems like some of you have been successful .
I have tried to follow the instructions/steps mentioned here, but i'm really confused by now.

Could you please help me get along ? ( It'd be gr8 if i could compile the HelloWorld successfully )

It'd be nice if steps could be provided to accomplish the HelloWorld compilation
---for example which download should i use ( from svn or from the sourceforge or the cmake version.

I will then go through the steps and report back if still have problems.
There is a problem with the way that GL/freeglut.h is included. Here is a patch file to fix the problem by making a small modification to the existing makefiles. You should be able to get a working Testbed by:
1. Check out the current tree in SVN
2. Apply this patch by going to the top-level directory and running "patch -p0 < freeglut.patch".
3. Run "make"
Thanks for replying, kavaler !
However, i still couldn't get the "make" to work, as it failed with errors.

I have attached the output dump of the make command ( BOTH BEFORE and AFTER applying the PATCH ).
I believe it'll be helpful to debug the problem i'm going through. Please do take a look if possible ! 🙂
It looks like the patch was not applied properly. Did you run "patch -p0" (the 0 is a zero). I can tell because the command for compiling freeglut is missing the "-I." which is the thing I added in the patch. Specifically

cc -g -O2 -DTARGET_HOST_UNIX_X11 -DHAVE_FCNTL_H -DHAVE_SYS_IOCTL_H -c -o freeglut_callbacks.o freeglut_callbacks.c

should be

cc -g -O2 -DTARGET_HOST_UNIX_X11 -DHAVE_FCNTL_H -DHAVE_SYS_IOCTL_H -I. -c -o freeglut_callbacks.o freeglut_callbacks.c
I did as follows
$ patch -p0 < freeglut.patch
patching file Contrib/freeglut/Makefile
patching file Examples/TestBed/Makefile

to make sure i did a check
$ cat Contrib/freeglut/Makefile | grep DHAVE_SYS_IOCTL_H
CFLAGS= -g -O2 -DTARGET_HOST_UNIX_X11 -DHAVE_FCNTL_H -DHAVE_SYS_IOCTL_H -I.

and it still fails with the make. i've attached the dump again
This one's pretty long, so bear with me 🙂

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