Pan C ++ development: How to Use C ++ to write cross-platform applications

Source: Internet
Author: User
Tags wxwidgets

Pan C ++ development: How to Use C ++ to write cross-platform applications

Slogan:One encoding, compilation everywhere!:-)

One encoding, which is completed on vc7.1, VI, and even ulteredit.

Compile everywhere.CodeCopy to other operating systems can also be compiled and run without having to modify even a line of code.

Does it sound like sun. In fact, the portability of C ++ is deemed to be more than that of Java. The reason why Java is famous is that B .s makes it clear: the interests of vendors.

 

Well, you don't need to talk nonsense.

 

It is also difficult and easy to build a C ++ cross-platform application.

What are the difficulties? The so-called application is a practical application and involves a wide range of topics. Generally, we need to consider at least the following aspects:

0. Language and basic library

1. Operating System related

2. Network

3. Database

4. Interface

There are many other things, such as XML and encryption/Decryption. Here we will first discuss the items listed above.

As we all know, different operating systems may have the same functions in real time. For example, parameters and returned values have different definitions (socket), and even different semantics (sleep. If you need to maintain the difference on your own, you must write the following code:

# If defined winnt

# Elif defined Linux

...

This is definitely a huge project. As for how big the project is, you can take a look at Ace development costs. This is hard!

In order to realize my slogan, what I want to do is to find a cross-platform library that has been proven by everyone's practices to help with coding. It is easy to build on the shoulders of giants. Some of my options are listed one by one below:

0. Language and base library:

Standard C ++ and boost

The standard C ++ was developed in 98 years. Currently, the mainstream C ++ compilers support it well. Vc7.1 and gcc4.0 and later are recommended. Boost is a set of C ++ libraries built up by a group of C ++ standards committees. Many of these libraries are imported into C ++ tr1, which can be said to be quasi-standard. We have a good reason to use the library here. For string-like operations, you can use the boost string algorithms library. for formatting operations, you can use boost: format and the regular expression boost: RegEx. Boost content is quite rich, please refer to the specific content of the http://www.boost.org/libs/libraries.htm here there is a list of boost library.

1. Operating System related:

ACE (Adaptive Communication Environment) and boost

Ace encapsulates the mutex, signal, process, and thread related to the operating system and can be used directly. However, if Ace is not usedProgramIt is related to the network. Ace may not be used when the network is not used. At this time, you can consider using the corresponding boost class thread: thread, boost.: process, etc.

2. Network

Ace

Ace is very good for network applications. In addition to simple packaging for heterogeneous platforms, there are also design models to cope with various environments. It can even be said that C ++ is currently the only choice for cross-platform network programming. ACE also provides packaging for high performance requirements such as iocp (winnt) or epoll (linux2.6.

3. Database

OTL (Oracle, ODBC and DB2-CLI Template Library)

To support databases, not only cross-platform, but also cross-database, is it more ideal than you think. OTL supports the following databases: OTL Oracle, SQL Server, access, and MySQL. There are other libraries such as DTL, but I think this library not only supports ODBC, but also supports native database interfaces, which can provide better performance.

4. Interface

Qt, wxWidgets

Although I have been using MFC for many years, I still hate the countless macros of MFC. Although wxWidgets is good, its style is obvious. Use QT. object-oriented programming is quite pleasant. However, QT is a two-way authentication. If your program is free of charge, it will be free of charge. If your program is going to sell money, it will also need it, and the price is very high. Therefore, wxWidgets can be considered for copyright and cost considerations.

I have listed many things and hope to help you. However, note that the number of platforms supported by each database is small and inconsistent. You need to estimate the platform that may be used for application. However, it is enough in general. The above Library supports at least two types of files: Windows and Unix/Linux. Here, we can basically migrate the programs we write in Windows and Linux"One encoding, compilation everywhere! ".

 

Related

ACE: http://www.cs.wustl.edu /~ Schmidt/ace.html

Boost: http://www.boost.org/

OTL: http://otl.sourceforge.net/

Qt: http://www.trolltech.com/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.