简体   繁体   中英

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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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