SFML和Box2D不兼容

问题描述 投票:0回答:1

所以,我正在学习使用Box2D,并且为了渲染我使用SFML,但我遇到了一些问题。注意:我在Windows 10上使用Visual Studio 2017,以及最新版本的SFML和Box2D。

我在Box2D手册中创建了一个接地盒:

b2Vec2 gravity(0.0f, -9.81f);
b2World world(gravity);

b2BodyDef groundBodyDef;
groundBodyDef.position.Set(50.0f, 100.0f);

b2Body* groundBody = world.CreateBody(&groundBodyDef);
b2PolygonShape groundBox;
groundBox.SetAsBox(50.0f, 10.0f);
groundBody->CreateFixture(&groundBox, 0.0f);

还有一些SFML代码用于创建一个窗口,运行游戏循环并创建一个sf::RectangleShape对象,它与groundBox位于同一个地方,但是我不知道如何做到这一点,所以当时我只是使用神奇的数字。

RenderWindow window;
window.create(VideoMode(640, 480),"Test for Box2D");
Event event;

//Box----------------------------------
RectangleShape box(Vector2f(100.0f, 20.0f));
box.setPosition(50.0f, 100.f);
box.setFillColor(Color::Red);


//Game loop---------------------------
while (window.isOpen()) {
    //window closure
    while (window.pollEvent(event)) {
        if (event.type == Event::Closed) {
            window.close();
        }
    }

    //////// Drawing  ////////
    window.clear();
    //------------------------------------------
    window.draw(box);
    //------------------------------------------
    window.display();
}

我的问题是链接错误;如果我使用x86,我会得到一堆Box2D错误,最后这个:

warning LNK4272: library machine type 'x64' conflicts with target machine 'x86'
fatal error LNK1120: 11 unresolved externals

这是我得到的一些错误:

`Source.obj : error LNK2001: unresolved external symbol "public: virtual 
class b2Shape * __thiscall b2PolygonShape::Clone(class b2BlockAllocator 
*)const " (?Clone@b2PolygonShape@@UBEPAVb2Shape@@PAVb2BlockAllocator@@@Z)`

Source.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall b2PolygonShape::GetChildCount(void)const " (? GetChildCount@b2PolygonShape@@UBEHXZ)

Source.obj : error LNK2019: unresolved external symbol "public: void __thiscall b2PolygonShape::SetAsBox(float,float)" (? SetAsBox@b2PolygonShape@@QAEXMM@Z) referenced in function _main

Source.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall b2PolygonShape::TestPoint(struct b2Transform const &,struct b2Vec2 const &)const " (? TestPoint@b2PolygonShape@@UBE_NABUb2Transform@@ABUb2Vec2@@@Z)

所以我尝试将其更改为x64,然而我受到了欢迎:

sfml-graphics-d.lib(sfml-graphics-d-2.dll) : fatal error LNK1112: module machine type 'x86' conflicts with target machine type 'x64'

我多次检查以确保包含lib和include目录,还检查其他dependacies和权利.dll SFML文件到Build(Debug)文件夹中。我不知道问题出在哪里,所以非常感谢任何帮助!

c++ box2d sfml
1个回答
0
投票

你似乎在混合x86和x64程序集。

如果要使用x64编译器创建应用程序,则需要为Box2D和SFML获取x64的预构建二进制文件。

如果要使用x86编译器创建应用程序,则需要为Box2D和SFML获取x86的预构建二进制文件。

但是由于我没有看到Box2D预先构建的二进制文件,你可能编译了自己的二进制文件。那么你只需要确保在构建Box2D时选择正确的编译器。

© www.soinside.com 2019 - 2024. All rights reserved.