erincatto / box2d

Box2D is a 2D physics engine for games
https://box2d.org
MIT License
7.44k stars 1.47k forks source link

LINK : fatal error LNK1104: cannot open file 'box2d.lib' #751

Closed BiomedicLJZ closed 10 months ago

BiomedicLJZ commented 11 months ago

Make sure these boxes are checked before submitting your issue - thank you!

I've been trying to install and use the library for the last week and I've been unable to build a simple test program having the following error:

LINK : fatal error LNK1104: cannot open file 'box2d.lib' [D:\Documentos\UNIAT\Clases\Simulacion_fisicas2d\untitled\cmake-build-default-visual-studio\test.vcxproj]

I followed the CMake install guide with Program Files and then with in another location and the error keeps the same

FYI I'm using CLion 2023.1.5 with the following CMake Lists.txt:

cmake_minimum_required(VERSION 3.25)
project(test)

find_package(box2d CONFIG REQUIRED)

include_directories("D:/Documentos/UNIAT/packages")

set(CMAKE_CXX_STANDARD 17)

add_executable(test main.cpp)

target_link_libraries(test PRIVATE box2d)

and the following main code

#include <iostream>
#include "D:/Documentos/UNIAT/packages/include/box2d/box2d.h"
int main() {
    //Create the world
    b2Vec2 gravity(0.0f, -10.0f);
    b2World world(gravity);
    //Create the ground
    b2BodyDef groundBodyDef;
    groundBodyDef.position.Set(0.0f, -10.0f);
    b2Body* groundBody = world.CreateBody(&groundBodyDef);
    b2PolygonShape groundBox;
    groundBox.SetAsBox(50.0f, 10.0f);
    groundBody->CreateFixture(&groundBox, 0.0f);
    //Create the dynamic body
    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    bodyDef.position.Set(0.0f, 4.0f);
    b2Body* body = world.CreateBody(&bodyDef);
    b2PolygonShape dynamicBox;
    dynamicBox.SetAsBox(1.0f, 1.0f);
    b2FixtureDef fixtureDef;
    fixtureDef.shape = &dynamicBox;
    fixtureDef.density = 1.0f;
    fixtureDef.friction = 0.3f;
    body->CreateFixture(&fixtureDef);
    //Simulate the world
    for (int32 i = 0; i < 60; ++i) {
        world.Step(1.0f / 60.0f, 6, 2);
        b2Vec2 position = body->GetPosition();
        float angle = body->GetAngle();
        std::cout << position.x << " " << position.y << " " << angle << std::endl;
    }
    return 0;
}
Kostu96 commented 10 months ago

try linking to box2d::box2d instead of box2d

BiomedicLJZ commented 10 months ago

Thank you that was it