交叉编译

在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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值