Article Title: Experience in Porting a VC program to a Linux System. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
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.