'LNK2001 Error even though .cpp is being compiled

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?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source