简体   繁体   English

如何在Code :: Blocks / Mingw32(Windows)中构建Box2D

[英]How would I build Box2D to work in Code::Blocks/Mingw32(Windows)

hey the title pretty much says it all. 嘿,标题几乎说了一切。 i have been trying different methods from internet sources, but whenever i try something goes wrong..this is where i got Box2D 我一直在尝试不同的方法来自互联网来源,但每当我尝试出错时..这就是我得到Box2D的地方

in cMake , i get a bunch of errors when building it(i was going through the steps in the readme.txt, but onfortunately, theyre for Visual C++...) cMake中 ,我在构建它时遇到了一堆错误(我正在阅读readme.txt中的步骤,但很遗憾,它们是用于Visual C ++ ...)

so im wondering hot to set this up as i guess a library (.lib or .a) and use it in my project(my friend passed me his library and when i loaded it in and tried #include ing the box2D headers, they didnt read at all(i got a list of undefined errors) also his box2d was i believe made for linux/unix so i think thats the reason...) 所以我想知道设置这个,因为我猜一个库(.lib或.a)并在我的项目中使用它(我的朋友将我的文件传递给我,当我加载它并尝试#include ing box2D标题时,他们没有阅读(我有一个未定义的错误列表)也他的box2d我相信为linux / unix做了所以我认为这就是原因...)

if anyone can help provide some steps that would be nice. 如果有人可以帮助提供一些很好的步骤。

thanks for reading. 谢谢阅读。

Assumptions: You have installed cmake. 假设:您已经安装了cmake。 You have installed Code::Blocks/MinGW to C:\\codeblocks. 您已将Code :: Blocks / MinGW安装到C:\\ codeblocks。 You have downloaded Box2D and extracted it to C:\\Box2D_v2.1.2. 您已下载Box2D并将其解压缩到C:\\ Box2D_v2.1.2。

If any of those are wrong, modify the paths to match what you have. 如果其中任何一个出错,请修改路径以匹配您拥有的路径。

Start->Run->cmd. 开始 - >运行 - > CMD。

Navigate to the Box2D "Build" folder: 导航到Box2D“Build”文件夹:
cd C:\\Box2D_v2.1.2\\Box2D\\Build

Create the makefiles: 创建makefile:
cmake -G "MinGW Makefiles" ..

Do it: 这样做:
mingw32-make

This will throw some warnings, but should work almost completely. 这会引发一些警告,但几乎应该完全有效。 Then, near the end, it will error trying to compile the Testbed. 然后,接近结束时,尝试编译Testbed会出错。 AFAIK, there is no way to compile the Testbed using MinGW (you have to use Visual Studio, I believe). AFAIK,没有办法使用MinGW编译Testbed(我相信你必须使用Visual Studio)。 Luckily, an .exe of it is available on the Box2D site. 幸运的是,Box2D网站上提供了它的.exe文件。

In the Box2D\\Build\\Box2D folder, there should now be a file called libBox2D.a. 在Box2D \\ Build \\ Box2D文件夹中,现在应该有一个名为libBox2D.a的文件。 Copy this file into C:\\codeblocks\\mingw\\lib. 将此文件复制到C:\\ codeblocks \\ mingw \\ lib。

Copy the Box2D\\Box2D folder (the one containing Box2D.h) into C:\\codeblocks\\mingw\\include. 将Box2D \\ Box2D文件夹(包含Box2D.h的文件夹)复制到C:\\ codeblocks \\ mingw \\ include中。 [Thus, after this step, you should have a file C:\\codeblocks\\mingw\\include\\Box2D\\Box2d.h, and NOT C:\\codeblocks\\mingw\\include\\Box2d.h] [因此,在此步骤之后,您应该有一个文件C:\\ codeblocks \\ mingw \\ include \\ Box2D \\ Box2d.h,而不是C:\\ codeblocks \\ mingw \\ include \\ Box2d.h]

And that's it. 就是这样。 You should be able to compile and run the "Hello Box2D" example. 您应该能够编译并运行“Hello Box2D”示例。 Don't forget to link to the library. 别忘了链接到图书馆。

[EDIT] [编辑]

From the looks of your error, I'm going to guess that your MinGW Path environment variable is not setup correctly. 从错误的外观来看,我猜你的MinGW Path环境变量设置不正确。 Which is unusual, since when you install Code::Blocks/MinGW it usually sets it for you, I believe. 这是不寻常的,因为当你安装Code :: Blocks / MinGW时,它通常会为你设置它,我相信。

Anyway, (these steps may vary slightly depending on your version of Windows): 无论如何,(这些步骤可能会略有不同,具体取决于您的Windows版本):

Right-click on "[My] Computer"-> Properties -> Advanced System Settings 右键单击“[我的电脑” - >属性 - >高级系统设置
Click "Environment Variables" 点击“环境变量”
Depending on which Windows you have, you may see User Variables and System Variables, or it may be just one group (I can't remember the name). 根据您拥有的Windows,您可能会看到用户变量和系统变量,或者它可能只是一个组(我不记得名称)。 Anyway, create a new System Environment Variable called MINGDIR, with the value C:\\codeblocks\\mingw or wherever you installed it to. 无论如何,创建一个名为MINGDIR的新系统环境变量,其值为C:\\codeblocks\\mingw或安装它的位置。 Then, find the variable called Path (or PATH) and append this to the end: C:\\codeblocks\\mingw\\bin . 然后,找到名为Path(或PATH)的变量并将其追加到末尾: C:\\codeblocks\\mingw\\bin Put a semicolon at the end of the previous entry, and do not use a space. 在前一个条目的末尾加上一个分号,不要使用空格。
Also make sure that C:\\CMake\\bin is present in either the System Variable called Path, or the user variable called Path. 还要确保C:\\CMake\\bin出现在名为Path的系统变量或名为Path的用户变量中。 If not, append it to the end. 如果没有,请将其追加到最后。
I think that's it. 我想就是这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM