交叉编译

交叉编译详解 一 概念篇 本文总结了什么是交叉编译链,并介绍了交叉编译链的各个组成部分 阅读详情

在FreeBSD平台编译OpenWRT源码,发现还是对主系统有头文件或库的引用关系,不知道是交叉编译系统的问题还是软件包的问题。先研究一下交叉编译。

gcc交叉编译容易理解不到位的配置选项:

Options specification

Use options to override several configure time options for GCC. A list of supported options follows; ‘configure --help’ may list other options, but those not listed below may not work and should not normally be used.

//这些配置选项引自https://gcc.gnu.org/install/configure.html  上面一段说明除了这个网页列举的选项,其他选项不要用。实践中发现即使是列出的这些选项也可能出问题,可能是理解不完全没用对,也可能是源码本身有问题。

--prefix=dirname
    Specify the toplevel installation directory. This is the recommended way to install the tools into a directory other than the default. The toplevel installation directory defaults to /usr/local.

    We highly recommend against dirname being the same or a subdirectory of objdir or vice versa. If specifying a directory beneath a user's home directory tree, some shells will not expand dirname correctly if it contains the ‘~’ metacharacter; use $HOME instead.

    The following standard autoconf options are supported. Normally you should not need to use these options.

--with-local-prefix=dirname
    Specify the installation directory for local include files. The default is /usr/local. Specify this option if you want the compiler to search directory dirname/include for locally installed header files instead of /usr/local/include.

    You should specify --with-local-prefix only if your site has a different convention (not /usr/local) for where to put site-specific files.

    The default value for --with-local-prefix is /usr/local regardless of the value of --prefix. Specifying --prefix has no effect on which directory GCC searches for local header files. This may seem counterintuitive, but actually it is logical.

    The purpose of --prefix is to specify where to install GCC. The local header files in /usr/local/include—if you put any in that directory—are not part of GCC. They are part of other programs—perhaps many others. (GCC installs its own header files in another directory which is based on the --prefix value.)

    Both the local-prefix include directory and the GCC-prefix include directory are part of GCC's “system include” directories. Although these two directories are not fixed, they need to be searched in the proper order for the correct processing of the include_next directive. The local-prefix include directory is searched before the GCC-prefix include directory. Another characteristic of system include directories is that pedantic warnings are turned off for headers in these directories.

    Some autoconf macros add -I directory options to the compiler command line, to ensure that directories containing installed packages' headers are searched. When directory is one of GCC's system include directories, GCC will ignore the option so that system directories continue to be processed in the correct order. This may result in a search order different from what was specified but the directory will still be searched.

    GCC automatically searches for ordinary libraries using GCC_EXEC_PREFIX. Thus, when the same installation prefix is used for both GCC and packages, GCC will automatically search for both headers and libraries. This provides a configuration that is easy to use. GCC behaves in a manner similar to that when it is installed as a system compiler in /usr.

    Sites that need to install multiple versions of GCC may not want to use the above simple configuration. It is possible to use the --program-prefix, --program-suffix and --program-transform-name options to install multiple versions into a single directory, but it may be simpler to use different prefixes and the --with-local-prefix option to specify the location of the site-specific files for each version. It will then be necessary for users to specify explicitly the location of local site libraries (e.g., with LIBRARY_PATH).

    The same value can be used for both --with-local-prefix and --prefix provided it is not /usr. This can be used to avoid the default search of /usr/local/include.

    Do not specify /usr as the --with-local-prefix! The directory you use for --with-local-prefix must not contain any of the system's standard header files. If it did contain them, certain programs would be miscompiled (including GNU Emacs, on certain targets), because this would override and nullify the header file corrections made by the fixincludes script.

    Indications are that people who use this option use it based on mistaken ideas of what it is for. People use it as if it specified where to install part of GCC. Perhaps they make this assumption because installing GCC creates the directory.

--with-native-system-header-dir=dirname
    Specifies that dirname is the directory that contains native system header files, rather than /usr/include. This option is most useful if you are creating a compiler that should be isolated from the system as much as possible. It is most commonly used with the --with-sysroot option and will cause GCC to search dirname inside the system root specified by that option.


Cross-Compiler-Specific Options

The following options only apply to building cross compilers.

--with-sysroot
--with-sysroot=dir
    Tells GCC to consider dir as the root of a tree that contains (a subset of) the root filesystem of the target operating system. Target system headers, libraries and run-time object files will be searched for in there. More specifically, this acts as if --sysroot=dir was added to the default options of the built compiler. The specified directory is not copied into the install tree, unlike the options --with-headers and --with-libs that this option obsoletes. The default value, in case --with-sysroot is not given an argument, is ${gcc_tooldir}/sys-root. If the specified directory is a subdirectory of ${exec_prefix}, then it will be found relative to the GCC binaries if the installation tree is moved.

    This option affects the system root for the compiler used to build target libraries (which runs on the build system) and the compiler newly installed with make install; it does not affect the compiler which is used to build GCC itself.

    If you specify the --with-native-system-header-dir=dirname option then the compiler will search that directory within dirname for native system headers rather than the default /usr/include.

    //这个dirname应该是sysroot下的dirname,参照上面--with-native-system-header-dir=dirname选项的解释。

    gcc/Makefile.in中有下面源码:
    # Default native SYSTEM_HEADER_DIR, to be overridden by targets.
    NATIVE_SYSTEM_HEADER_DIR = @NATIVE_SYSTEM_HEADER_DIR@
    # Default cross SYSTEM_HEADER_DIR, to be overridden by targets.
    CROSS_SYSTEM_HEADER_DIR = @CROSS_SYSTEM_HEADER_DIR@

    configure中有下面源码:
    --with-native-system-header-dir=dir
       use dir as the directory to look for standard system header files in. Defaults to /usr/include.
    --with-sysroot[=DIR]
       search for usr/lib, usr/include, et al, within DIR

    if test -n "$configured_native_system_header_dir"; then
       native_system_header_dir=$configured_native_system_header_dir
    fi
       NATIVE_SYSTEM_HEADER_DIR="$native_system_header_dir"


    CROSS_SYSTEM_HEADER_DIR='$(TARGET_SYSTEM_ROOT)$${sysroot_headers_suffix}$(N ATIVE_SYSTEM_HEADER_DIR)'

    # Check whether --with-sysroot was given.
    if test "${with_sysroot+set}" = set; then :
       withval=$with_sysroot;
       case ${with_sysroot} in
          yes) TARGET_SYSTEM_ROOT='${exec_prefix}/${target_noncanonical}/sys-root' ;;
          *) TARGET_SYSTEM_ROOT=$with_sysroot ;;
       esac


交叉编译详解 在嵌入式开发中,经常会提到交叉编译,那么什么是交叉编译?和我们本地编译有什么区别呢?怎么使用交叉编译工具呢?在问题之前,我们先简单说明下编译,用本地编译来对比说明。在程序开发中,使用高级语言编写的代码被称为源代码,比如用C语言编写的后缀名为.c的文件,或者C++编写的后缀名为.cpp的文件。源代码不能被机器执行,必须转换成二进制的机器代码(指令+数据)才能被CPU执行。将源代码转换成机器代码的过程称为编译(Compile),编译的工作需要编译器(Complier)来完成。编译器对源代码进行语法检查,只有没有 阅读详情

相关推荐

树莓派交叉编译

树莓派交叉编译

weixin_54859557的博客 1731

gcc编译规则

gcc编译规则文档是linux系统所有gcc编译选项的集合。

交叉编译工具链介绍

基本概念 什么是交叉编译 交叉编译可以理解为,在当前编译平台下,编译出来的程序能运行在体系结构不同的另一种目标平台上,但是编译平台本身却不能运行该程序。 比如,我们在 x86 平台上,编写程序并编译成能运行在 ARM 平台的程序,编译得到的程序在 x86 平台上是不能运行的,必须放到 ARM 平台上才能运行。 交叉编译链就是为了编译跨平台体系结构的程序代码而形成的由多个子工具构成的一套完整的工具集。同时,它隐藏了预处理、编译、汇编、链接等细节,当我们指定了源文件(.c)时,它会自动按照编译流程调用不同的子

sinan1995的博客 5558

gcc查找头文件的规则

见:http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html /usr/local/include libdir/gcc/target/version/include /usr/target/include /usr/include libdir是{prefix}/lib,target是a

但是博客很漂亮 6810

首次 LFS 搭建全过程

LFS 是什么? LFS(英文 Linux From Scratch 的缩写),中文释意为“从零开始构建的 Linux”。好吧!看起来很高大上 OTZ,可它到底是什么东西呢?感觉上它好像经常和 RedHat,Debain 这类发行版混在一起,那它应该也是个发行版吧! 这样理解其实也没有什么不对,但比起发行版来,它其实更像一本书。书本只提供知识,它只教你做,不会帮你做。这才是 LFS 和别的发行版的本质区别。这本书可以教你如何亦步亦趋的从零开始搭建一个具体而微的 Linux 系统,没错,就是从零开始,是..

Yonx 8120

关于foss-for-synopsys-dwc-arc-processors工具链中GCC 14包含目录问题的技术分析

关于foss-for-synopsys-dwc-arc-processors工具链中GCC 14包含目录问题的技术分析 在foss-for-synopsys-dwc-arc-processors工具链项目中,使用GCC 14编译器时出现了一个关于包含目录路径处理的异常问题。这个问题表现为编译器在构建过程中尝试访问不存在的系统头文件目录路径,导致构建过程出现警告信息。 该问题的核心在于GCC 14编...

gitblog_07765的博客 464

mingw-gcc-9.0.1-i686-posix-sjlj-201903

-------------------------------------------------------------------------------gcc version 9.0.1 20190322-77e3616 (experimental) --enable-sjlj-exceptions ----------------------------------------------...

weixin_33753845的博客 529

riscv 各种版本 gcc 工具链编译与安装

riscv的gcc编译器,分为2大类:裸机: unknown-elf,none-embed除了 none-embed 编译器,对于每一类,如果禁用 multilib,那么又分为 32 位版本和 64 位版本。如果使能 multilib,那么就只有一个版本,但是这个版本工具,可以同时支持 32 位和 64 位。

ppqppl的博客 8830

一文搞懂交叉编译,Windows和Linux的交叉编译

在一种计算机环境中运行的编译程序,能编译出在另外一种环境下运行的代码,我们就称这种编译器支持交叉编译。这个编译过程就叫交叉编译。简单地说,就是在一个平台上生成另一个平台上的可执行代码。这里需要注意的是所谓平台,实际上包含两个概念:体系结构(Architecture)、操作系统同一个体系结构可以运行不同的操作系统;同样,同一个操作系统也可以在不同的体系结构上运行。举例来说,我们常说的x86Linux平台实际上是Intel x86体系结构和Linux for x86操作系统的统称;

qq_41854911的博客 1万+

交叉编译概念

交叉编译是指在一个平台上编译代码,使其能够在另一个不同的平台上运行的过程。这种编译方式通常用于开发嵌入式系统、移动设备和其他受限环境中的应用程序。交叉编译是使用一种编译器(称为交叉编译器),该编译器在宿主机(host)上运行,但生成的目标代码却可以在目标机(target)上运行。宿主机和目标机通常有不同的硬件架构和操作系统环境。()嵌入式系统:如物联网设备、路由器、工业控制器等。移动设备:如智能手机、平板电脑等。特定架构的服务器:如ARM服务器。操作系统开发:如为不同架构编译Linux内核。

studyingdda的博客 4447

交叉编译】什么是交叉编译,为何要有交叉编译

交叉编译,就是:在一种平台上编译,编译出来的程序,是放到别的平台上运行即编译的环境,和运行的环境不一样,属于交叉的,此所谓 cross。

Cappuccino Blog 7669

什么是交叉编译,为什么要使用交叉编译?

一、什么是交叉编译        在一种计算机环境中运行的编译程序,能编译出在另外一种环境下运行的代码,我们就称这种编译器支持交叉编译。这个编译过程就叫交叉编译。简单地说,就是在一个平台上生成另一个平台上的可执行代码。这里需要注意的是所谓平台,实际上包含两个概念:体系结构(Architecture)、操作系统(OperatingSystem)。同一个体系结构可以运行不同的操作系统;同样,同一个操

mars1743的专栏 2万+

交叉编译简介

经常说交叉编译交叉编译的,它究竟是什么呢?转载一篇基础知识对于没有做过嵌入式编程的人,可能不太理解交叉编译的概念,那么什么是交叉编译?它有什么作用?在解释什么是交叉编译之前,先要明白什么是本地编译。本地编译本地编译可以理解为,在当前编译平台下,编译出来的程序只能放到当前平台下运行。平时我们常见的软件开发,都是属于本地编译:比如,我们在 x86 平台上,编写程序并编译成可执行程序。这种方式下,我们使用 x86 平台上的工具,开发针对 x86 平台本身的可执行程序,这个编译过程称为本地编译。

同步更新https://blog.must-xin.com/,内容转载请联系作者本人 4322

5temporary_system

LFS的编译就正式开始了Are you ready??Binutils这时第一反应应该是: 文件还是tar.bz或xz的, 还没解包呢, 切到sources目录解吧tar -xvf binutils-2.25.tar.bz2如果你一目十行的话, 估计已经等不及看到了后面初看到这里, 也会不解的。不对,肯定有什么忽略掉了, 注意一下上面的Important 也就不难懂了 安装软件时, 首先

YuHao Feng的专栏 446

交叉工具链制作至尊宝典

转自:http://blog.csdn.net/turui/article/details/6596093     一些必须知道的基础知识 Debian 操作系统 以及 aptitude 命令autoconf and automake什么是交叉编译,configure 的几个参数 build host target build: 编译代码的机器,的CPU指令集 host:

1992

编译MinGW版GCC

Ive made this little guide to get a working MinGW gcc-4.0.3 up to gcc-4.1.2 (should work with binutils too)i did have the latest build on my googlepage but it ran out of bandwidth, unless anybody can

蜗牛档案室 4940

linux 工具链路径,linux工具链要点.md

[TOC]# linux 工具链要点(lfs)## 前言在lfs(自己构建linux发行版)中,需要大量的编译,繁重的编译,且环环相扣,很容易出现问题,从头开始。而这里面最关键的就是构建工具链,如果工具链出现问题,下面的编译也将出现问题,而且这个问题并没有想象中那么容易暴露出来,直到你突然发现无法运行或者无法编译。## 工具链主要部件### 目标系统三段式1. 机器 $(uname -m) #x8...

weixin_42513170的博客 766
上一篇: openwrt配置文件的疑惑
下一篇: openwrt barrier_breaker gcc final编译配置选项好像有问题
cleanwrt
博客等级 码龄12年 10粉丝 20原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值