简体   繁体   English

从OS X交叉编译到Linux

[英]Cross-compile to Linux from OS X

I want to compile binaries for a Linux server from an OS X 10.7 + Eclipse build system. 我想从OS X 10.7 + Eclipse构建系统编译Linux服务器的二进制文件。 This means a GCC cross-compiler. 这意味着GCC交叉编译器。 I'm starting from native 4.7.1 and shooting for a host 4.7.1. 我从本机4.7.1开始,为主机4.7.1射击。

Most online instructions are specific to embedded development. 大多数在线说明都特定于嵌入式开发。 I want to use libstdc++-v3 and glibc, which make it a little different. 我想使用libstdc ++ - v3和glibc,这使它有点不同。

What succeeds: 成功的是什么:

  1. Install packages 安装包

     port install gcc47 export CC=gcc-mp-47 export LD=ld-mp-47 export CXX=g++-mp-47 export CPP=cpp-mp-47 port install gmake ln /opt/local/bin/gmake /opt/local/bin/make port install gsed ln /opt/local/bin/gsed /opt/local/bin/sed port install gawk port install autoconf port install msgfmt 
  2. Make and install binutils-2.22 制作并安装binutils-2.22

  3. make all-gcc and make install-gcc make all-gccmake install-gcc

    Used the following config: 使用以下配置:

    $ ../gcc/configure --enable-languages=c,c++,objc,obj-c++ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --prefix=/usr/local/cross/linux --target=x86_64-pc-linux-gnu --disable-nls $ ../gcc/configure --enable-languages = c,c ++,objc,obj-c ++ --with-gmp = / opt / local --with-mpfr = / opt / local --with-mpc = / opt / local --prefix = / usr / local / cross / linux --target = x86_64-pc-linux-gnu --disable-nls

  4. Point the build environment at the cross-compiler 将构建环境指向交叉编译器

     export CC=/usr/local/cross/linux/bin/x86_64-pc-linux-gnu-gcc export LD=/usr/local/cross/linux/bin/x86_64-pc-linux-gnu-ld export AR=/usr/local/cross/linux/bin/x86_64-pc-linux-gnu-ar export CXX=/usr/local/cross/linux/bin/x86_64-pc-linux-gnu-g++ export CPP=/usr/local/cross/linux/bin/x86_64-pc-linux-gnu-cpp 
  5. Build glibc-2.16 using the config 使用config构建glibc-2.16

    ../glibc/configure --host=x86_64-pc-linux-gnu --build=x86_64-apple-darwin11 --prefix=/usr/local/cross/linux/ --with-binutils=/usr/local/cross/linux/bin/ --with-headers=/usr/local/cross/linux/include/ libc_cv_forced_unwind=yes libc_cv_ctors_header=yes libc_cv_c_cleanup=yes ../glibc/configure --host = x86_64-pc-linux-gnu --build = x86_64-apple-darwin11 --prefix = / usr / local / cross / linux / --with-binutils = / usr / local / cross / linux / bin / --with-headers = / usr / local / cross / linux / include / libc_cv_forced_unwind = yes libc_cv_ctors_header = yes libc_cv_c_cleanup = yes

The failure: 失败:

glibc build fails before long. glibc构建不久就失败了。 This message appears many times: 此消息多次出现:

In file included from ./sysdeps/unix/sysdep.h:20:0,
                 from ./sysdeps/unix/x86_64/sysdep.h:18,
                 from sysdeps/unix/sysv/linux/x86_64/sysdep.h:22,
                 from <stdin>:1:
sysdeps/unix/sysv/linux/sys/syscall.h:24:24: fatal error: asm/unistd.h: No such file or directory
compilation terminated.

This may be normal, though. 不过,这可能是正常的。

Then it fails to produce stdio_lim.h . 然后它无法生成stdio_lim.h With make -d , I get this: 使用make -d ,我得到这个:

          Successfully remade target file `/Users/dkrauss/Documents/work/glibc-build/csu/abi-tag.h'.
          Considering target file `/Users/dkrauss/Documents/work/glibc-build/bits/stdio_lim.h'.
           File `/Users/dkrauss/Documents/work/glibc-build/bits/stdio_lim.h' does not exist.
           Looking for an implicit rule for `/Users/dkrauss/Documents/work/glibc-build/bits/stdio_lim.h'.
           Trying pattern rule with stem `lim'.
           Trying implicit prerequisite `/Users/dkrauss/Documents/work/glibc-build/bits/stdio_lim.st'.
           Found an implicit rule for `/Users/dkrauss/Documents/work/glibc-build/bits/stdio_lim.h'.
            Considering target file `/Users/dkrauss/Documents/work/glibc-build/bits/stdio_lim.st'.
            Recently tried and failed to update file `/Users/dkrauss/Documents/work/glibc-build/bits/stdio_lim.st'.
make[2]: *** No rule to make target `/Users/dkrauss/Documents/work/glibc-build/bits/stdio_lim.st', needed by `/Users/dkrauss/Documents/work/glibc-build/bits/stdio_lim.h'.  Stop.

This is the first header it attempts to build in bits . 这是它尝试以bits为单位构建的第一个头。 There is a file stdio_lim.h.in , which is the only .in file in its directory. 有一个文件stdio_lim.h.in ,它是目录中唯一的.in文件。 Should some rule be connecting .st to .in ? 如果有些规则是连接.st.in

In order to properly build glibc, you need the header files from a Linux system - probably the kernel headers are sufficient. 为了正确构建glibc,您需要来自Linux系统的头文件 - 可能内核头文件就足够了。

This is due to the fact that those headers are needed in any normal build of the software for that system, and the same is no different when cross-compiling. 这是因为在该系统的软件的任何正常构建中都需要这些头,并且在交叉编译时也是如此。

It's been a long time since I worked on creating cross-compilers, so I can't tell you how to get the build of glibc to see the headers, but I believe it can be done in a straight-forward manner. 自从我创建交叉编译器以来已经很长时间了,所以我不能告诉你如何使用glibc来构建标题,但我相信它可以直接进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM