[Solved] Using box2D with Qt creator

Hi everyone,

I want to use box2d with Qt creator 5.1.1. With all examples on the internet I was able to build and run the example (testbed) by following this tutorial http://qtsimplify.blogspot.ch/2013/02/b ... th-qt.html. But when I try to use box2d in my own project (with all #include) but when I create my World, I have a build error:

undefined reference to `b2World::b2World(b2Vec2 const&)
undefined reference to `b2World::~b2World()
undefined reference to `b2World::~b2World()'
error: ld returned 1 exit status

here is my main.cpp
Code:
#include "mainwindow.h"
#include <QApplication>
#include <Box2D/Box2D.h>
#include <Box2D/Dynamics/b2World.h>


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    // Define the gravity vector.
    b2Vec2 gravity(0.0f, -10.0f);

    // Construct a world object, which will hold and simulate the rigid bodies.
    b2World world(gravity);
    w.show();

    return a.exec();
}


I tried with different version of Box2d, tried to download ".lib" and added them in my project but nothing works. I probably do something wrong but I can't find out.

So... How am I supposed to make box2d works in my own Qt project?
Since you have built and run the testbed, you will already have the box2d library ready to use. It will probably be in the Build/Box2D folder, called libBox2D.a

You can add a few lines to your Qt .pro file to tell it where the library is. Here is a piece from the .pro file I use:
Code:
INCLUDEPATH += ../libs/Box2D
LIBS += -L"../libs/Box2D/Build/Box2D"
LIBS += -lBox2D

Of course, you'll need to change the paths - they should be relative to the location of the .pro file.
Yeeey!!

it works now! Thanks dude 😉

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