0

I'm working on a project where I'm using Bullet3 to add a Physics Simulation Component-System to EntityX.

I'm getting link errors when compiling code, and I can't quite figure out why. Both my header PhysicsSystem.h and the source PhysicsSystem.cpp are in the project, and I can see them both being linked as a .obj in the intermediate files.

The header file PhysicsSystem.h:

    class PhysicsSystem : public entityx::System<PhysicsSystem>, public entityx::Receiver<PhysicsSystem> {
    public:
      void configure(entityx::EntityManager &entities, entityx::EventManager &events) override;
      void update(entityx::EntityManager& entities, entityx::EventManager& events, entityx::TimeDelta dt) override;
      void receive(const entityx::ComponentAddedEvent<RigidBody>& event);
      void setGravity(ci::vec3 gravity);
      btDiscreteDynamicsWorld* getWorld();
    private:
      btDefaultCollisionConfiguration* mCollisionConfiguration;
      btCollisionDispatcher* mDispatcher;
      btBroadphaseInterface* mOverlappingPairCache;
      btSequentialImpulseConstraintSolver* mBulletSolver;
      btDiscreteDynamicsWorld* mDynamicsWorld;
    };

and PhysicsSystem.cpp:

void PhysicsSystem::configure(entityx::EntityManager &entities, entityx::EventManager &events) {
      ///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration.
      mCollisionConfiguration = new btDefaultCollisionConfiguration();
      ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
      mDispatcher = new btCollisionDispatcher(mCollisionConfiguration);
      ///btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep.
      mOverlappingPairCache = new btDbvtBroadphase();
      ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
      mBulletSolver = new btSequentialImpulseConstraintSolver();
      mDynamicsWorld = new btDiscreteDynamicsWorld(mDispatcher, mOverlappingPairCache, mBulletSolver, mCollisionConfiguration);
      mDynamicsWorld->setGravity(btVector3(0.0, 0.0, 0.0));

      events.subscribe<entityx::ComponentAddedEvent<RigidBody>>(*this);
}

void PhysicsSystem::update(entityx::EntityManager& entities, entityx::EventManager& events, entityx::TimeDelta dt) {
    mDynamicsWorld->stepSimulation(static_cast<float>(dt), 10);
}

void PhysicsSystem::receive(const entityx::ComponentAddedEvent<RigidBody>& event) {
    mDynamicsWorld->addRigidBody(event.component->getRigidBody());
}

void PhysicsSystem::setGravity(ci::vec3 gravity) {
    if (mDynamicsWorld != nullptr) {
        mDynamicsWorld->setGravity(btVector3(gravity.x, gravity.y, gravity.z));
    }
    else {
        std::printf("PhysicsSystem ERROR -- must configure() system before you can set parameters.\n");
    }
}

btDiscreteDynamicsWorld* PhysicsSystem::getWorld() {
    return mDynamicsWorld;
}

When I try to compile I get the errors:

Error   LNK2001 unresolved external symbol "public: virtual void __cdecl PhysicsSystem::configure(class entityx::EntityManager &,class entityx::EventManager &)" (?configure@PhysicsSystem@ecs@sitara@@UEAAXAEAVEntityManager@entityx@@AEAVEventManager@5@@Z)   PhysicsSystemExample    C:\Project\physics\examples\PhysicsSystemExample\vc2013\PhysicsSystemExampleApp.obj 1   

Error   LNK2001 unresolved external symbol "public: virtual void __cdecl PhysicsSystem::update(class entityx::EntityManager &,class entityx::EventManager &,double)" (?update@PhysicsSystem@ecs@sitara@@UEAAXAEAVEntityManager@entityx@@AEAVEventManager@5@N@Z) PhysicsSystemExample    C:\Project\physics\examples\PhysicsSystemExample\vc2013\PhysicsSystemExampleApp.obj 1   

Error   LNK2019 unresolved external symbol "public: void __cdecl PhysicsSystem::setGravity(struct glm::tvec3<float,0>)" (?setGravity@PhysicsSystem@ecs@sitara@@QEAAXU?$tvec3@M$0A@@glm@@@Z) referenced in function "public: virtual void __cdecl PhysicsSystemExampleApp::setup(void)" (?setup@PhysicsSystemExampleApp@@UEAAXXZ)    PhysicsSystemExample    C:\Project\physics\examples\PhysicsSystemExample\vc2013\PhysicsSystemExampleApp.obj 1   

Relatedly, I get a link warning 4042:

Severity    Code    Description Project File    Line    Suppression State
Warning LNK4042 object specified more than once; extras ignored PhysicsSystemExample    C:\Project\physics\examples\PhysicsSystemExample\vc2013\build\x64\Debug\intermediate\PhysicsSystem.obj  1   

But I only have the file added once, and can't find the file specified a second time. Why would the file be specified more than once?

What other steps can I take to troubleshoot why I'm having a linkage problem?

skink
  • 5,133
  • 6
  • 37
  • 58
nathan lachenmyer
  • 5,298
  • 8
  • 36
  • 57
  • It appears you have two files named `PhysicsSystem.cpp`, in different directories, both added to the project. Look for that. – Igor Tandetnik Mar 15 '20 at 02:59
  • I looked in `PhysicsSystemExample.vcxproj` and `PhysicsSystemExample.vcxproj.filters` and only saw once instance in each. Even searched in my hard drive and just found one copy of the file on there. – nathan lachenmyer Mar 15 '20 at 03:06
  • Why have you tagged this for Visual Studio 2015 but the folder is named `vc2013`? I ask because you can't mix 2013 and 2015 binaries. They are incompatible. – drescherjm Mar 15 '20 at 03:39
  • In project property: Linker-> Input -> Additional dependencies: You update Linker -> General ->Additional Library Directories – Build Succeeded Mar 15 '20 at 08:49
  • 1
    Please share PhysicsSystemExampleApp code where you are using PhysicsSystem. Are you using static instance of PhysicsSystem? – nkvns Mar 15 '20 at 09:24
  • Removing and re-adding `PhysicsSystem.h` and `PhysicsSystem.cpp` seems to have resolve the issue -- not sure how or why this was an issue! – nathan lachenmyer Mar 16 '20 at 14:54

0 Answers0