开发者

Creating a Cross-Platform C++ Library

开发者 https://www.devze.com 2022-12-22 05:00 出处:网络
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 an

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. I'm working on the windows enviroment with Visual C++ Express 2008, so it would be n开发者_开发百科ice if I can use Visual C++ Express as the IDE.

My platforms are YET the Nintendo DS and the 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. Like on Windows, it will generate the project files to use Visual Studio; on Linux, it will generate the GNU make files for you. You can set it up to find the right versions of the right libraries and everything. Cmake is great.

CMake is not a compiler (neither is make) - it is a cross-platform build automation system. 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. Using Boost can help keep all your code working smoothly on any system and there is basically no overhead to using it.


I know you can use Makefiles to do #defines, which is, in turn, a common trick for swapping out chunks of code. There are also ways to detect the platform, although that's mostly for Mac/Windows/Linux differences.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号