错误LNK2019无法解析的外部符号“公共:类b2Body * __thiscall b2World :: CreateBody(struct b2BodyDef const *)”(?CreateBody @ b2World @@ QAEPAVb2Body @@ PBUb2BodyDef @@@@ Z)在函数_main Project8中引用
每次调用box2d函数时,类似的错误将增加12个。我认为链接库存在一些错误,但是找不到它。
它也说
警告LNK4272库机器类型'x64'与目标机器类型'x86'冲突
和一些(60)警告,例如
警告C26495变量'b2Color :: a'未初始化。始终初始化成员变量(类型6)。
我尝试过的方法: 我已经使用premake5 vs2019构建了sln文件,然后通过打开该sln并构建测试平台项目来构建了库文件(我将配置设置为debug并发布win32,我都建立了两个都没有用)我也只使用了box2D项目来构建测试台也无法正常工作。 代码中似乎没有问题,因为我尝试了自己的尝试,还尝试了box2d中helloword.cpp中附带的错误,我在上面写过其中的错误
#include "Box2D/Box2D.h"
#include <stdio.h>
int main(int argc, char** argv)
{
B2_NOT_USED(argc);
B2_NOT_USED(argv);
// Define the gravity vector.
b2Vec2 gravity(0.0f, -10.0f);
b2World world(gravity);
// Define the ground body.
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);
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);
float32 timeStep = 1.0f / 60.0f;
int32 velocityIterations = 6;
int32 positionIterations = 2;
for (int32 i = 0; i < 60; ++i)
{
world.Step(timeStep, velocityIterations, positionIterations);
b2Vec2 position = body->GetPosition();
float32 angle = body->GetAngle();
printf("%4.2f %4.2f %4.2f\n", position.x, position.y, angle);
}
system("PAUSE");
return 0;
}