简体   繁体   English

创建跨平台C ++库

[英]Creating a Cross-Platform C++ Library

I wanted to create a cross-platform 2D game engine, and I would like to know how to create a cross-platform project with Makefile, so I can compile it to the platforms I choose with custom rule for any platform. 我想创建一个跨平台的2D游戏引擎,并且我想知道如何使用Makefile创建一个跨平台的项目,因此我可以使用针对任何平台的自定义规则将其编译为我选择的平台。 I'm working on the windows enviroment with Visual C++ Express 2008, so it would be nice if I can use Visual C++ Express as the IDE. 我正在使用Visual C ++ Express 2008在Windows环境上工作,因此,如果我可以将Visual C ++ Express用作IDE,那就太好了。

My platforms are YET the Nintendo DS and the PC. 我的平台是任天堂DS和PC。

Please instruct me what to do. 请指示我该怎么办。

Thanks in advance, Tamir. 在此先感谢,塔米尔。

Don't use make, use a cross-platform tool like cmake, it will take care of the platform-specific generation for you. 不要使用make,使用像cmake这样的跨平台工具,它将为您解决特定于平台的问题。 Like on Windows, it will generate the project files to use Visual Studio; 像在Windows上一样,它将生成项目文件以使用Visual Studio。 on Linux, it will generate the GNU make files for you. 在Linux上,它将为您生成GNU make文件。 You can set it up to find the right versions of the right libraries and everything. 您可以对其进行设置,以找到正确的库和所有内容的正确版本。 Cmake is great. Cmake很棒。

CMake is not a compiler (neither is make) - it is a cross-platform build automation system. CMake不是编译器(也不是make)-它是一个跨平台的构建自动化系统。 It allows you to develop on any platform and it defaults to assuming you're developing for the platform you're running. 它允许您在任何平台上进行开发,并且默认情况下假设您正在为所运行的平台进行开发。 You can specify parameters if you want to do other things. 如果要执行其他操作,则可以指定参数。 However, most of the "cross-platform" stuff is still left to your code. 但是,大多数“跨平台”内容仍然留给您的代码。 I would also recommend a library that has been tested on many platforms, like Boost . 我还建议使用已经在许多平台上经过测试的库,例如Boost Using Boost can help keep all your code working smoothly on any system and there is basically no overhead to using it. 使用Boost可以帮助您确保所有代码在任何系统上都能顺利运行,并且基本上没有使用开销。

I know you can use Makefiles to do #defines, which is, in turn, a common trick for swapping out chunks of code. 我知道您可以使用Makefiles来执行#defines,这反过来是换出代码块的常见技巧。 There are also ways to detect the platform, although that's mostly for Mac/Windows/Linux differences. 尽管主要针对Mac / Windows / Linux差异,但是也有检测平台的方法。

Also, Travis is probably right; 同样,特拉维斯可能是正确的。 having your makefiles themselves be cross-platform is really excellent, since it's easier to then setup build servers and things. 使自己的makefile跨平台确实非常好,因为这样可以更轻松地设置构建服务器和事物。

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

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