[SOLVED] AND ANSWERS POSTED re: Ubuntu can't build!

I downloaded the zip from here:
https://github.com/erincatto/Box2D

Which is called Box2D-master

in terminal I navigate to Box2D-master/Box2D/Box2D/Build

then I run

cmake ..


which works fine, no errors


then make

Runs almost to the end and then has a couple errors


Code: Select all

[  1%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Joints/b2DistanceJoint.cpp.o
[  3%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Joints/b2FrictionJoint.cpp.o
[  4%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Joints/b2GearJoint.cpp.o
[  6%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Joints/b2Joint.cpp.o
[  7%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Joints/b2MotorJoint.cpp.o
[  9%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Joints/b2MouseJoint.cpp.o
[ 11%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Joints/b2PrismaticJoint.cpp.o
[ 12%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Joints/b2PulleyJoint.cpp.o
[ 14%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Joints/b2RevoluteJoint.cpp.o
[ 15%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Joints/b2RopeJoint.cpp.o
[ 17%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Joints/b2WeldJoint.cpp.o
[ 19%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Joints/b2WheelJoint.cpp.o
[ 20%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Contacts/b2CircleContact.cpp.o
[ 22%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Contacts/b2Contact.cpp.o
[ 23%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Contacts/b2ContactSolver.cpp.o
[ 25%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Contacts/b2PolygonAndCircleContact.cpp.o
[ 26%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Contacts/b2EdgeAndCircleContact.cpp.o
[ 28%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp.o
[ 30%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Contacts/b2ChainAndCircleContact.cpp.o
[ 31%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Contacts/b2ChainAndPolygonContact.cpp.o
[ 33%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/Contacts/b2PolygonContact.cpp.o
[ 34%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/b2Body.cpp.o
[ 36%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/b2ContactManager.cpp.o
[ 38%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/b2Fixture.cpp.o
[ 39%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/b2Island.cpp.o
[ 41%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/b2World.cpp.o
[ 42%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/b2WorldCallbacks.cpp.o
[ 44%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Common/b2BlockAllocator.cpp.o
[ 46%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Common/b2Draw.cpp.o
[ 47%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Common/b2Math.cpp.o
[ 49%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Common/b2Settings.cpp.o
[ 50%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Common/b2StackAllocator.cpp.o
[ 52%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Common/b2Timer.cpp.o
[ 53%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Collision/Shapes/b2CircleShape.cpp.o
[ 55%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Collision/Shapes/b2EdgeShape.cpp.o
[ 57%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Collision/Shapes/b2ChainShape.cpp.o
[ 58%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Collision/Shapes/b2PolygonShape.cpp.o
[ 60%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Collision/b2BroadPhase.cpp.o
[ 61%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Collision/b2CollideCircle.cpp.o
[ 63%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Collision/b2CollideEdge.cpp.o
[ 65%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Collision/b2CollidePolygon.cpp.o
[ 66%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Collision/b2Collision.cpp.o
[ 68%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Collision/b2Distance.cpp.o
[ 69%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Collision/b2DynamicTree.cpp.o
[ 71%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Collision/b2TimeOfImpact.cpp.o
[ 73%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Rope/b2Rope.cpp.o
Linking CXX static library libBox2D.a
[ 73%] Built target Box2D
Scanning dependencies of target HelloWorld
[ 74%] Building CXX object HelloWorld/CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o
Linking CXX executable HelloWorld
[ 74%] Built target HelloWorld
Scanning dependencies of target glew
[ 76%] Building C object glew/CMakeFiles/glew.dir/glew.c.o
In file included from /home/parallels/Downloads/Box2D-master/Box2D/glew/glew.c:37:0:
/home/parallels/Downloads/Box2D-master/Box2D/glew/glxew.h:100:21: fatal error: GL/glew.h: No such file or directory
 #include <GL/glew.h>
                     ^
compilation terminated.
make[2]: *** [glew/CMakeFiles/glew.dir/glew.c.o] Error 1
make[1]: *** [glew/CMakeFiles/glew.dir/all] Error 2
make: *** [all] Error 2




Has anyone had this issue? I'm stuck.

I thought about premake4, premake5 which i tried to run but I guess you need a .lua file so it knows how to build



I tried:

premake5 gmake

which said

Code: Select all

No Premake script (premake5.lua) found!




I've been pulling my hair out trying to compile this for days. Any help would be greatly appreciated!
I got it. Even though those errors occur, they're related to the testbed thats setup with open gl for windows or something.

It does indeed compile the lib.a file.

Figured out how to link everything up.

I'm going to leave how I fixed it here, because I'm sick of people responding to their own threads
"got it" and no answers. c++ world seems to be full of that lol..




So here's how I fixed it:
code::blocks on ubuntu. (process is very similar in other IDEs)



Run what I posted above (even though those errors occur)
It does make the .a file
[EDIT ITS NOT above, my bad. Look below I posted it in later reply]


in code::blocks
right click your project and select "Build Options"

goto "Linker settings" tab

there are two layouts
"Link Libraries" and "Other linker options" shows up

To my understanding "Link Libraries" is for static libraries (which box2D is)
"other linker options" is to list lookup names for DLLs to connect to at run-time

add box2d in left side

MAKE SURE you do this for DEBUG AND RELEASE!



Now make sure in your project you add an "include" or "headers" folder.

Copy the entire Box2D source code directory into that folder in your project directory
Now by hand, delete ALL .cpp files. Only keep the headers (.h)
I also deleted the CMakeList stuff. In your header folder you should only see Box2D.h and then the folders Collision, Common, Dynamics, Rope

make sure that whole Box2D folder is the same structure as downloaded just with only the .h files for your project.



NOW


you need to make sure you tell code::blocks where these header files actually are.
You have to tell it TWICE.
(I don't fully understand the compile process, but there's linker and compiler that are different steps in the compile processs, and they BOTH need to be made aware of the .h files!)

So back in your "project build options" (right click your project, "Build Options")
go to Search directors tab

you'll see 3 tabs inside there

Compiler / Linker / Resource Compiler

BOTH compiler and linker need the location of your headers to successfully compile.
In both "compiler" and "linker" tabs, add your include / header directory. (the file that contains the Box2D folder thats full of the .h files)

Other thing to note is you have to do this for DEBUG and RELEASE!
(just like when you added the .a file in linker settings for both debug and release)



That is it! It feels like a lot the first time you try to link up libs / headers in compiler / linker etc.
I struggled a lot and if you don't know what you're even googling for, its hard to find answers.

So hopefully this gets you connected up if you've been having issues!
I really REALLY wish that http://www.cplusplus.com/doc/tutorial/
would put up some basic pages on how compiler / linker flow chart work ( i know you can google for this )
and actually walk you through how it works, and teach you how to link static AND dynamic libraries in some tutorials, because this was a PAIN in the ASS

Best of luck out there!
Oh I just noticed that I didn't include the building part:

So here's what I did for that to create the .a file in the first place.

this is on ubuntu, so i used apt-get to make sure i have the correct tools. Other linux uses yum so try it out and see what you have


make sure you have the following (you may not need all these but i used all these)

(EACH of these will do a quick download, and ask you Y/N to install hit y enter and let her go for each)

Code: Select all

sudo apt-get install g++
sudo apt-get install build-essential
sudo apt-get install cmake


If it tells you you are missing any other commands just sudo apt-get whatever it says its missing
(or yum if you have another linux distro)


once that is all installed

download the box2d zip (mine says master version) I downloaded from the github page


unzip it

in terminal navigate to it and make sure when you run : ls
you see
Box2D
Build
Documentation
glew
glfx
HelloWorld.. etc

I made a folder "build" (theres already Build cap B, but i made another 'build' with lower case b)

if you're total linux newb (like i was)

: mkdir build


then

:cd build


now you're ready to run

Code: Select all

cmake ..


what that means is cmake will look in the directory one directory up for how to build this thing and build it where you are (you are in the build lower case b folder)

let it do its thing. You'll see the errors I posted about in my original post, don't worry about it

Now without leaving that directory. type

Code: Select all

make

and hit enter.

FYI cmake .. just PREPS the compile. I think it builds .o files etc, and preps the real compiler to build the thing. "make" is the moment it actually creates the lib file




inside the lowercase b build folder there should be a Box2D folder containing Box2D.a or whatever its called

(the one .a lib file there is, find it)


THAT is what you put in your libs folder in your project so that you can link it in linker settings



I know its a huge pain in the ass if you're never done it. hence me spelling it out as much as i can to help you get there if you're new to this

Again best of luck.

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