Why c ++ cross-platform development?
From the two projects I participated in, the underlying libraries are generally required to be cross-platform. The upper UI Layer can adopt the existing cross-platform UI framework or the unique UI framework of the Platform (to better use the platform features)
The C ++ underlying library encapsulates a large number of Io operations, or the APIS required for product development. In this way, code can be reused to reduce the cost of cross-platform development.
In addition, the development and maintenance of core APIs can be well controlled by a single team to better control risks and quality.
Cross-platform
Generally, we use the C ++ STD library, which is developed by the International c ++ Standards Committee. It should be supported by all compilers.
However, when we encounter some libraries and functions that are unique to compilers on some Linux and Windows platforms, we need to treat them differently.
1. Many people use macros to control related tasks.Code. However, when there are a lot of platform differences, the code is very messy, and macros are everywhere, so you will lose your appetite.
2. To avoid the above problems, we can separate platform differences and use them as two sets of implementation files. Then, the precompiled macro is used to control which header file to reference. This looks much clearer.
3. Recently, in a new project, we found a cross-platform tool cmake. We can directly reference related files for related platforms in cmake. Let macros take effect when generating related projects.
This makes it clearer.
4. cross-platform lib can be used. For example, boost and QT are cross-platform. It is very convenient to use. Qt not only writes a large number of C ++ libraries, but also its UI framework is cross-platform. Therefore, it is widely used in cross-platform UI development.