因此,我正在学习使用Box2D,并使用SFML进行渲染,但是遇到了一些问题。注意:我正在Windows 10以及最新版本的SFML和Box2D上使用Visual Studio 2017。
我已经创建了一个类似于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目录,还检查其他依赖项并将.dll SFML文件正确地放入Build(调试)文件夹。 我不知道问题出在哪里,所以我们将不胜感激!
答案 0 :(得分:0)
您似乎在混合使用x86和x64程序集。
如果要使用x64编译器创建应用程序,则需要获取Box2D和SFML的x64预置二进制文件。
如果要使用x86编译器创建应用程序,则需要获取Box2D和SFML的x86预先构建的二进制文件。
但是,由于我没有看到Box2D的预构建二进制文件,因此您可能编译了自己的二进制文件。然后,您只需要确保在构建Box2D时选择了正确的编译器即可。