search
HomeComputer TutorialsComputer KnowledgeHow to cross-compile executable programs of different systems on ubuntu server?

I believe many C programmers have had this question, what if a server has different gcc versions? Will they affect each other?

The answer is yes. When we generally use gcc to compile source files, this gcc is the first gcc found in the system environment variable PATH.

What if you want to cross-compile programs for different systems? This requires multiple sets of compilation tool chains, and the corresponding tool chains are used to compile the programs of the target system.

Default path

  • Compiler path: usually placed in the /usr/bin directory.
  • Header file path: System-level header files are usually placed in /usr/include, and standard library header files are generally placed in /usr/local/include.
  • Library path: System dynamic libraries are often located at /usr/lib and /lib, and static libraries are usually placed here or /usr/local/lib.

Manually set the path

Compiler path

Changing the environment variable for the compiler path is usually not necessary since /usr/bin should already be in your PATH environment variable. If you need to use a different compiler, you can directly use its full path or modify the PATH environment variable to point to your compiler, for example:

export PATH=/path/to/your/compiler:$PATH

This will add the path you specify in front of the existing PATH so that the system will first look for the executable file here.

Set up the cross compiler

I need to compile ARM architecture programs on Ubuntu, using the tool chain provided by Marvell. This toolchain contains gcc and other tools for cross-compiling ARM architecture programs, all with the same prefix.

arm编译:这样设置前缀后就可以使用交叉编译器
export CROSS_COMPILE=/home/zheng/marvell-tools-12006.0/bin/aarch64-marvell-linux-gnu-

使用环境变量进行编译:

${CROSS_COMPILE}gcc-o hello_arm hello_arm.c

How to cross-compile executable programs of different systems on ubuntu server?

How to cross-compile executable programs of different systems on ubuntu server?View executable program system architecture

Then execute these two programs respectively:

How to cross-compile executable programs of different systems on ubuntu server?

Current system architecture: uname -m

How to cross-compile executable programs of different systems on ubuntu server?

Generally gcc will follow the system's default PATH path to find the corresponding tool components required for compilation.

So if you want to compile programs with different architectures, you need multiple sets of tool chains. If you add the paths of these tool chains to the system environment variable PATH, there will be a conflict , which will take precedence. Use the tool with the same name in the previous path, for example, the PATH is set to:

export PATH=/path/arm_toolchain/bin:/usr/bin:/path/x86_toolchain/bin

/path/arm_toolchain/bin and /usr/bin, /path/x86_toolchain/bin all have tools named gcc, then the former ones will overwrite the following , and each execution will take priorityUse the earliest matching gcc tool.

Disadvantages: Compilation tool chains of different architectures cannot be dynamically specified, and the PATH environment variable needs to be modified frequently.

Improvement method: Specify the corresponding environment variables for each tool chain, so that different compilers can be dynamically distinguished.

This method is suitable for temporarily switching tool chains and compiling programs with different architectures. If it is a large C program, the path to the compiler is generally specified in the configuration file, and then built using make, meson and other build tools.

The above is the detailed content of How to cross-compile executable programs of different systems on ubuntu server?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:每日运维. If there is any infringement, please contact admin@php.cn delete
Must-Know Fixes - Cannot Type Password on the Login ScreenMust-Know Fixes - Cannot Type Password on the Login ScreenApr 24, 2025 am 12:50 AM

Unable to type password at login screen Windows 7/8/10/11? Why does this issue occur? What should you do when you cannot type password on the login screen? This post from php.cn provides you with several feasible solutions to this matter.

[Solved] macOS Cannot Verify That This App Is Free from Malware - MiniTool[Solved] macOS Cannot Verify That This App Is Free from Malware - MiniToolApr 24, 2025 am 12:49 AM

Have you encountered the “macOS cannot verify that this app is free from malware” notification when running apps on Mac? This post from php.cn shows you how to solve this problem.

3 Targeted Solutions for Error Code 2000-0415 on Dell3 Targeted Solutions for Error Code 2000-0415 on DellApr 24, 2025 am 12:48 AM

Error code 2000-0415 is a small issue that is connected to some specific cables of your computer. It is pretty common in Dell devices. If you receive this error at the moment, the tips and tricks of this post on php.cn Website will be helpful to you.

Computer Freezes But Mouse Still Moves - Results-Driven MethodsComputer Freezes But Mouse Still Moves - Results-Driven MethodsApr 24, 2025 am 12:47 AM

Have you ever encountered a situation where the computer freezes but mouse still moves? Many people are troubled by this problem and they choose to forcefully shut down their computers. In fact, there are other methods that can help you solve this pr

Windows 7 Ultimate SP1 Free Download and Install (32/64 Bits) - MiniToolWindows 7 Ultimate SP1 Free Download and Install (32/64 Bits) - MiniToolApr 24, 2025 am 12:46 AM

Some users still use the Windows 7 edition and they want to download Windows 7 Ultimate SP1. However, they don’t know where to find the ISO file. Don’t worry! This post from php.cn tells you how to free download and install  Windows 7 Ultimate SP1.

Is Your Spectrum DVR Not Working? Try These Fixes! - MiniToolIs Your Spectrum DVR Not Working? Try These Fixes! - MiniToolApr 24, 2025 am 12:45 AM

What will you do if there is a conflict between your favourite TV shows and work appointments? Spectrum DVR can help you out! It allows you to record your favourite games or TV shows and watch them whenever you want. If you are plagued by Spectrum DV

How to Enable Selection Checkboxes in File Explorer Windows 10 - MiniToolHow to Enable Selection Checkboxes in File Explorer Windows 10 - MiniToolApr 24, 2025 am 12:44 AM

Do you have any idea how to show or remove checkboxes in File Explorer? If not, you’ve come to the right place. This paper on php.cn shows you a couple of feasible ways to enable selection checkboxes in File Explorer.

5 Fixes for VSS Error 0x800423F4 When Backup in Win10/115 Fixes for VSS Error 0x800423F4 When Backup in Win10/11Apr 24, 2025 am 12:43 AM

VSS error 0x800423F4 happens when creating a system image on Windows 11/10. If you are plagued by this annoying issue, follow the fixes collected by php.cn to root out it. Besides, professional Windows backup software like php.cn ShadowMaker is intro

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment