CodeTyphon version:

6.0

Download: http://www.pilotlogic.com/codetyphon/zips/CodeTyphonIns.zip

Host operating system: Windows10 X64 Enterprise Edition

The host operating system is the operating system currently used to develop and compile FreePascal programs. All program development, compilation, and testing required for compilation are completed in this operating system. Then, in this operating system, without any modification to the source code, Compile the program in the target operating system.

Target operating system: Ubuntu16.04 X64

The target operating system is an operating system that actually executes the compiled program after the executable program is generated in the host operating system. The cross-compiled program is the executable file in the operating system.

Description: CodeTyphon cross-compilation should be able to compile any operating system it supports in any operating system it supports! ! The official recommendation is to cross-compile other operating systems under Linux. Do not cross-compile the Linux operating system under Windows, because Linux changes too fast! ! The operating system I am currently working on is Windows10 X64 Enterprise Edition. Ubuntu16.04 X64 is installed in the VM virtual machine, so I use Windows10 X64 Enterprise Edition as the host operating system and Ubuntu16.04 X64 as the target operating system! !

My CodeTyphon installation directory:

“C:\codetyphon”, the following CodeTyphon installation directory refers to this directory. When you look up the CodeTyphon installation directory yourself, you need to pay attention to whether it is the same as my installation directory!


CodeTyphon is really a powerful platform, only you can’t think of it, no it can’t do it! ! !

In order to use a set of source code, without any changes, in different operating systems to generate programs, I used two methods to achieve! ! ! !

1  install CodeTyphon on different operating systems:

How to install CodeTyphon on different operating systems: 

How to install CodeTyphon on every platform on different OS

This method is relatively simple and practical. After developing the program in an operating system (writing, compiling, and testing are correct), finally copy the program source code to the operating system to be compiled, and then open the project with CodeTyphon, and at any time. Just like CodeTyphon in the operating system, you can compile directly, and then you get the executable file in this operating system.

Advantages: During the compilation process, it is easy to find out whether there is a lack of support libraries required by the current operating system to run FreePascal programs, and these problems can be solved during the compilation process.

Disadvantages: CodeTyphon needs to be installed in each operating system.

Although this method is more troublesome to install CodeTyphon, I recommend that you compile the FreePascal program in this way, because it is easy to find problems during the compilation process, and it is easy to solve the problems that need to be solved in the actual running program in advance, so as not to wait for the operation. There was a problem with the program, so I didn’t know what went wrong! ! !

The above method as long as you will install CodeTyphon, you can achieve, not the focus of the discussion here, the following is the focus of this article! ! ! !


2, implement cross-compilation with CodeTyphon:

The purpose of cross-compilation is to develop and compile programs on an operating system, and then generate programs in other operating systems without changing the operating system of the development tools and compilers, and without modifying any source code! ! This is really a piece of cake for CodeTyphon! ! !

1, the tool to prepare to compile the target operating system program.

2. Prepare a library to compile the target operating system program.

3. Prepare to compile the unit file that the target operating system program needs to reference.

4. Configure the project compilation properties.

To achieve cross-compilation with CodeTyphon, you must go through 4 steps, which are indispensable! ! For cross-compilation of the same host operating system to the target operating system, if cross-compilation has been completed and cross-compilation is performed again, the first three of these steps should not be needed. Just pay attention to check the compilation project configuration properties. Yes! ! !

Below I will explain the above four steps in detail:

Get the tools and libraries needed to compile:

1, automatically obtained in CodeTyphon:

Advantages: Intuitive, auto-complete, no need to figure out the detailed process of getting and how to configure it.

Disadvantages: It is not always possible to get a successful one. Once again, you need to kill the previously launched wget program.

2, go directly to the CodeTyphon company website to download:

Advantages: You can use the download tool of the resume of the breakpoint to get a high success rate.

Disadvantages: You need to know the tools and libraries to get these needs, how to configure them, and configure them correctly!

CodeTyphon does not provide cross-compiled tools and libraries by default, which is also very easy to understand:

A, easy to download and install: CodeTyphon does not know which operating system you want to cross-compile, in order to reduce the size of the CodeTyphon installation package, easy to download and install CodeTyphon faster, so there is no more tools and libraries needed for cross-compilation.

B, customization is more convenient and casual: users can customize the CodeTyphon cross-compilation environment according to their own needs.

For the two ways to get the tools and libraries needed for compilation, I will explain them in the following two steps 1 and 2, which are explained in detail below:

1, the tools to prepare to compile the target operating system program:

Compilation tools are required to compile programs for the target operating system! ! ! Then I will use two ways to get the tools to compile the target operating system program! ! !

A, automatically obtained in CodeTyphon:

(1) Open the interface for downloading the cross-compiler tool: In the CodeTyphon menu, select “CrossBuild”->”Download Cross Toolchains”.

Step by step FreePascal-CodeTyphon cross-compilation

Step by step FreePascal-CodeTyphon cross-compilation

(2) In the open cross-compiler tool interface, select the menu “Actions”->”Get Server file List”.

Step by step FreePascal-CodeTyphon cross-compilation

Step by step FreePascal-CodeTyphon cross-compilation

(3), get the list of tools needed for cross-compilation: click on the menu “Actions”->”Get Server file List”, wait a moment, there will be a bunch of lists in the original blank space, these are all CodeTyphon support operations System cross compilation tool! !

Step by step FreePascal-CodeTyphon cross-compilation

Step by step FreePascal-CodeTyphon cross-compilation

(4), select and download the required cross-compilation tool: Click “Start Download”, use the taskbar icon or menu item to perform this operation, then start to select the downloaded cross-compiler tool, I chose “win32- I386-linux.7z”.

(5), download cross-compiler tool: After starting the download, CodeTyphon’s command window continuously scrolls through various download information, and at the same time creates some downloaded files, including the cross-compiler tool compressed file we want to download. According to their respective network conditions, this download time is not the same, you can wait patiently, this tool compression package is not big, less than 4 trillion, it should be downloaded in a little while! ! !

A, CodeTyphon is downloading a screenshot of the cross-compiler tool.

B, CodeTyphon download screenshots of various file usage tools: wget, in the task manager, we can clearly see that this download tool is running! ! !

(6) After downloading successfully, check the downloaded cross-compilation tool. After the download is successful, CodeTyphon will extract the downloaded cross-compilation tool to the directory corresponding to the name of the compressed package in “C:\codetyphon\binToolchains”. The directory where I downloaded the cross-compiler is: “C:\codetyphon\binToolchains\ Win32-i386-linux”. I open this directory and you will see all the tools for cross-compilation of Ubuntu16.04 X64! ! !

Step by step FreePascal-CodeTyphon cross-compilation

Step by step FreePascal-CodeTyphon cross-compilation

Note the problem: It is possible that the network condition is not good or other reasons cause wget not to download the cross-compilation tool we need. At this time, we need to end the task of the currently executing download task in the task manager. wget does not follow CodeTyphon. Exit automatically and quit! ! ! Then follow the above operation again and download again! ! !

B, go directly to the CodeTyphon website to download: Since CodeTyphon downloads these cross-compilation tools from the network, can we find the download address of the corresponding tool, without CodeTyphon, directly download it with other breakpoints? Yes, pilotlogic considers it very well and provides download addresses for all cross-compiler tools!

Cross Compilation Tools Download Address:  http://www.pilotlogic.com/sitejoom/index.php/downloads/category/5-toolchains

(1) Select the host operating system. I am currently using the Typhon 32-bit IDE, so I chose “Windows32”.

Step by step FreePascal-CodeTyphon cross-compilation

Step by step FreePascal-CodeTyphon cross-compilation

(2) After selecting the cross-compiler to download, download it with your favorite breakpoint tool.

Step by step FreePascal-CodeTyphon cross-compilation

Step by step FreePascal-CodeTyphon cross-compilation

(3), extract the successfully downloaded cross-compilation tool into the “C:\codetyphon\binToolchains” directory, be sure to store these tools in the “binToolchains” directory and the same name of the downloaded compressed package, and finally The cross-compiler tool stored in the manual download directory is: “C:\codetyphon\binToolchains\win32-i386-linux”.

Step by step FreePascal-CodeTyphon cross-compilation

Step by step FreePascal-CodeTyphon cross-compilation

Ok, the manual download is also complete, both of which can be downloaded to the cross-compiler tool, choose it according to the actual situation! ! !

2. Prepare a library to compile the target operating system program.

A, automatically obtained in CodeTyphon:

(1) Open the interface for downloading the cross-compilation library: In the CodeTyphon menu, select “CrossBuild”->”Download OSes Libraries”.

Step by step FreePascal-CodeTyphon cross-compilation

Step by step FreePascal-CodeTyphon cross-compilation

(2) In the Open Cross Compilation Library program interface, select the menu “Actions”->”Get Server file List”.

 

(3), get the list of libraries needed for cross-compilation: click on the menu “Actions”->”Get Server file List”, wait a moment, there will be a bunch of lists in the original blank space, these are all CodeTyphon support operations System library.

 

(4), select and download the required cross-compilation library: Click “Start Download”, use the taskbar icon or menu item to perform this operation, then start to select the downloaded cross-compilation library, I chose “i386- Linux.7z”.

 

(5), download the cross-compilation library: After starting the download, CodeTyphon’s command window continuously scrolls through various download information, and at the same time creates some downloaded files, including the cross-compiled library compressed files we want to download. According to their respective network conditions, this download time is not the same, you can wait patiently, this tool compression package is not big, less than 4 trillion, it should be downloaded in a little while! ! !

A, CodeTyphon is downloading a screenshot of the cross-compilation library.

 

B, CodeTyphon download screenshots of various file usage tools: wget, in the task manager, we can clearly see that this download tool is running! ! !

 

(6) After downloading successfully, check the downloaded cross-compilation library. After the download is successful, CodeTyphon will extract the downloaded cross-compiled library to the directory corresponding to the compressed package name in “C:\codetyphon\binLibraries”. I downloaded the cross-compiled library corresponding directory: “C:\codetyphon\binLibraries\ I386-linux”. I open this directory and you will see all the libraries that are cross-compiled for Ubuntu16.04 X64! ! !

Step by step FreePascal-CodeTyphon cross-compilation

Step by step FreePascal-CodeTyphon cross-compilation

Note the problem: It is possible that the network condition is not good or other reasons cause wget not to download the cross-compilation tool we need. At this time, we need to end the task of the currently executing download task in the task manager. wget does not follow CodeTyphon. Exit automatically and quit! ! ! Then follow the above operation again and download again! ! !

B, directly to the CodeTyphon company website download: cross-compilation tools can be manually downloaded online, the library can also be manually downloaded online!

Cross-compile library download address: http://www.pilotlogic.com/sitejoom/index.php/downloads/category/3-libraries 

(1) Select the library corresponding to the target operating system. I want to generate Ubuntu programs, so I chose “i386-linux.7z”. After the selection is complete, click on “Download” at the back and download the library file with your favorite breakpoint resume tool.

 

(3), extract the successfully downloaded cross-compiled library into the “C:\codetyphon\binLibraries” directory, be sure to store these library files in the “binToolchains” directory and the directory of the same name as the downloaded compressed package. The cross-compiled inventory directory for this manual download is: “C:\codetyphon\binLibraries\i386-linux”.

 

Ok, the manual download is also complete, these two methods can be downloaded to the cross-compilation library, choose according to the actual situation! ! !

3. Prepare to compile the unit file that the target operating system program needs to reference: After the tools and libraries are ready, you must prepare to compile the unit files of the target operating system program.

(1) Select “CrossBuild”->”FreePascal 32Bits”->”FPC32 build corss element i386-linux” from the CodeTyphon menu. This is the unit file that I need to compile for the corresponding target operating system. If you are not sure which one is needed, then you can select the top item “FPC32 build corss element ALL”, which will compile all the units that support compilation. Files, such compilation time should be longer, as long as you wait patiently for compilation!

Note: Be sure to select the unit that matches the number of bits in the current Typhon. The Typhon I am using is 32-bit, so I chose “FreePascal 32Bits”.

 

(2) Screenshot of the compilation process.

 

(3) Compile the screenshot. After compiling, the compile window disappears and returns to the main CodeTyphon interface.

 

4, configuration project compilation properties: After completing the above steps, you want to complete the cross-compilation, you also need to set the project properties, after setting, we can freely compile the program for the compiled platform!

Start Typhon first, this is our IDE to compile FreePascal! !

(1), the project state before cross-compilation: At this time, I have finished writing and compiling this program code in windows, and successfully generated the program under windows: “project1.exe”, now the project directory and inside There is no executable file under Linux like “project”, “project” is the executable file under Linux that I want to compile! !

 

(2), open the project properties. Click on Typhon’s menu “Project” -> “Project Options”.

 

(3), add linux compiler properties in the project properties dialog. Click “compiler Options” on the left, then check “Build modes” on the right, then click the button “…” at the back of the peer, then click the button “+”, then change the value of the name to “linux”. Click the “OK” button.

Step by step FreePascal-CodeTyphon cross-compilation

Step by step FreePascal-CodeTyphon cross-compilation

(4) Click the “…” button after the text box below “Libraries”. In the Select Directory dialog box that pops up, select the cross-compiled library directory we downloaded. My library directory is: “C:\codetyphon\binLibraries\i386-linux”.

 

(5) Click the “Add” button and click the “OK” button.

Step by step FreePascal-CodeTyphon cross-compilation

Step by step FreePascal-CodeTyphon cross-compilation

(6) After confirming that the compilation requires the library path to be correctly added, click the “OK” button.

Step by step FreePascal-CodeTyphon cross-compilation

Step by step FreePascal-CodeTyphon cross-compilation

(7) Click on the “Config and Targer” item on the left, then select “Build modes” on the right side as “linux”, then select “Targer OS” as “linux” and then select “Target CPU family” “i386”, then click the “OK” button.

Step by step FreePascal-CodeTyphon cross-compilation

Step by step FreePascal-CodeTyphon cross-compilation

(8), click “Run”->”Build” in the Typhon menu, cross-compilation starts, and finally the results are cross-compiled successfully! ! ! !

 

3, verify the cross-compiler in Ubuntu16.04 X64: 

 

Start Ubuntu16.04 X64 in the VM virtual machine, then copy the compiled “projec1” into it and execute it directly for verification! !

There is no reaction to execute “projec1”. Is it that cross-compilation fails and the generated executable file is not good? Execute the following test in the shell? As soon as I executed it, I found that there was an error. The error message is as follows:

Error while loading shared libraries: libgdk-x11- 2.0 .so. 0 : open open object  file : No such file or directory

The cause of the error: Because the library libgdk-x11-2.0.so.0 is missing, you should just install the corresponding library! !

Workaround: Install the missing library files.

Enter the following command in the shell:

Sudo apt-get install libgtk2. 0 - 0 :i386

After the library is installed, execute “projec1” again and it will run perfectly! ! ! Same as running in Windows10! ! ! ! Cross-compilation of Ubuntu on Windows 10 was successful! ! ! ! !

The program runs screenshots in linux:

 

Test program source code:

Copy code
Unit Unit1;

{ $mode objfpc }{ $H+ }

Interface

Uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;

Type

  { TForm1 }

  TForm1 = class(TForm)
    testLogBtn: TButton;
    clearBtn: TButton;
    logMemo: TMemo;
    leftPanel: TPanel;
    Panel2: TPanel;
    rightPanel: TPanel;
    Splitter1: TSplitter;
    Procedure clearBtnClick(Sender: TObject);
     procedure FormResize(Sender: TObject);
     procedure FormShow(Sender: TObject);
     procedure testLogBtnClick(Sender: TObject);
  Private
    // log method
     procedure Mylog(logInfo: string);

    / / Adjust the left pancel width
     procedure AdjustLeftPancelWidth;
  Public

  End ;

Var
  Form1: TForm1;

  logInfo: string; // log information variable

Implementation

{ $R *.lfm }

{ TForm1 }

Procedure TForm1.clearBtnClick(Sender: TObject);
 begin
  logmemo.Clear;
End ;

Procedure TForm1.FormResize(Sender: TObject);
 begin 
  // Adjust the width of the left panel
  self.AdjustLeftPancelWidth;
End ;

Procedure TForm1.FormShow(Sender: TObject);
 begin 
  // Adjust the width of the left panel
  self.AdjustLeftPancelWidth;
End ;

Procedure TForm1.testLogBtnClick(Sender: TObject);
 begin


  { $IFDEF windows } 
  logInfo: = ' current operating system: Windows ' ;
   { $ENDIF }

  { $IFDEF linux } 
  logInfo: = ' current operating system: linux ' ;
   { $ENDIF }

  { $IFDEF Darwin } 
  logInfo: = ' current operating system: Mac OS ' ;
   { $ENDIF }

  { $IFDEF unix } 
  logInfo: = ' current operating system: unix ' ;
   { $ENDIF }

  self.Mylog(logInfo);
End ;

Procedure TForm1.Mylog(logInfo: string);
 var
  Temp: string;
  oldLog: string;
Begin 
  if trim(logInfo) <> ''  then 
  begin

    oldLog : = trim(logMemo.Text);
    logMemo.Clear;

    Temp : = FormatDateTime( ' yyyy-mm-dd hh:mm:ss ' , now) + '  ' + trim(logInfo);
     if oldLog = ''  then 
    begin
      logMemo.Lines.Add(temp);
      logMemo.Lines.Add( '' );
     end 
    else 
    begin
      logMemo.Lines.Add(temp);
      logMemo.Lines.Add( '' );
      logMemo.Lines.Add(oldLog);
    End ;

  End ;
 end ;

Procedure TForm1.AdjustLeftPancelWidth;
 begin 
  leftPanel.Width : = self.Width div  3 ;
 end ;

End .
Copy code

Reference materials:

1, http://askubuntu.com/questions/356605/ubuntu-64-bit-machinarium-error-while-loading-shared-libraries-libgtk-x11-2-0

2, http://www.pilotlogic.com/sitejoom/index.php/wiki/98-wiki/technical/cross-build

3 http://www.cnblogs.com/sunylat/p/6517629.html