How to port a VC program to LINUX

Source: Internet
Author: User
Some tips on porting a VC program to LINUX-Linux general technology-Linux programming and kernel information. The following is a detailed description. Sometimes I need to create programs that can be run in both LINUX and WINDOWS. In general, I will choose to complete the initial development on the WINDOWS platform. The graphic editing and debugging interfaces provided by VC are indeed much higher than those provided by GCC. After the test is completed, we start to port it to LINUX. There will be some notes during the porting process. Below are some of my experiences.

File Name
Because the ext2 file system is case sensitive to file names, the # include statement in the source file must be careful when you compile the file system. In the VC environment, the # include statement automatically generated by IDE, where all file names are in lower case. Therefore, you need to pay attention to this issue from the very beginning. Strictly use the case-sensitive file name format to avoid the error that the header file cannot be found during LINUX compilation.

Data Type
Do not use the unique data types of VC, such as _ int16, _ int32, and _ int64. You cannot guarantee that other compilers support them. Especially _ int64, it does simplify programming, but when your logic is full of such data types, changes become very difficult. Another problem is that we often use extended data types such as WORD, DWORD, INT, and UINT in VC, data Types that do not directly use compilers can improve portability between different platforms. But this type is not defined in LINUX? In fact, you only need to copy the statements defined for the data in windows. h and basetypes. h to a header file, and then include them in linux.

Keywords
Keywords are better to deal with. Any keyword with two underscores in VC, for example, _ asm is unique to VC. Try not to use them. If it is unavoidable, use # ifdef and # endif to write two versions for LINUX and WINDOWS.

Write MAKEFILE
You can use VC to export a makefile and modify it. However, I prefer to copy a segment from it to generate the GCC makefile, which is much faster than writing it manually.

Program Design Structure
This is definitely the biggest part of the porting process. Applications will inevitably use the services of the operating system. If Standard C/C ++ is used for writing, this is not a problem, but when we use multi-entry/thread and pipeline, or, this problem becomes more prominent when porting a windows gui program. We should lay a good foundation for program transplantation in terms of design.

To solve this problem, you must first understand the logic module of the application. Standard C/C ++ must be used for writing this module. At the same time, the number of threads used by the application is minimized, and the more threads, the more difficult it is to transplant. Separate the input and output modules. Finally, a control module is divided to interact with users.
Related Article

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.