when running
运行时
arm-none-linux-gnueabi-gcc -print-search-dirs | grep libraries | sed 's/:/\n/g'
I get the following output:
我得到如下输出:
libraries
=/opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/
/opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/lib/arm-none-linux-gnueabi/4.4.1/
/opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/lib/
/opt/codesourcery/arm-none-linux-gnueabi/libc/lib/arm-none-linux-gnueabi/4.4.1/
/opt/codesourcery/arm-none-linux-gnueabi/libc/lib/
/opt/codesourcery/arm-none-linux-gnueabi/libc/usr/lib/arm-none-linux-gnueabi/4.4.1/
/opt/codesourcery/arm-none-linux-gnueabi/libc/usr/lib/
and when cross-compiling some packages it would make my life MUCH easier to be able to append to these paths. I know about the -L option, and I would like to use it, but many packages don't respect it while cross compiling, moreover using it with codesourcery causes problems. (see end of this post for details). Basically I've got a whole directory tree with all the required files to compile packages, and I want to add that directory tree to the default search paths. E.g, so that -print-search-dirs will also output a path similar to:
当交叉编译一些包时,我的生活就会更容易被添加到这些路径中。我知道-L选项,我想使用它,但是很多包在交叉编译时不尊重它,而且使用codesourcery会导致问题。(详情请参阅本文的结尾)。基本上,我有一个完整的目录树,包含所有需要的文件来编译包,我想把这个目录树添加到默认的搜索路径中。E。g,因此-打印-搜索-dirs也将输出一条类似的路径:
/target/usr/lib
/target/lib
in addition to the paths already listed. I'm not looking for a codesourcey specific answer, since I have several toolchains I can work with.
除了已经列出的路径。我不是在寻找一个codesourcey的具体答案,因为我有几个可以使用的工具链。
For those who are curious, here is the error from a codesourcery installation:
对于那些好奇的人来说,这是一个codesourcery安装的错误:
arm-none-linux-gnueabi-gcc test.c
works
作品
arm-none-linux-gnueabi-gcc -L/usr/arm-unknown-linux-gnueabi/usr/lib test.c
fails with:
失败:
/lib/libc.so.6: file not recognized: File format not recognized
collect2: ld returned 1 exit status
so obviously it's grabbing libc from the host. I've seen this happen with more than one toolchain, but not all.
很明显,它从宿主那里夺走了libc。我见过不止一个工具链,但不是全部。
In response to a comment: Here is the output for
作为对评论的回应:这里是输出。
arm-none-linux-gnueabi-gcc -L/usr/arm-unknown-linux-gnueabi/usr/lib test.c -v -Wl,-verbose
Using built-in specs. Target: arm-none-linux-gnueabi Configured with: /scratch/julian/2010q1-release-linux-lite/src/gcc-4.4-2010q1/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi --enable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --enable-extra-sgxxlite-multilibs --with-arch=armv5te --with-gnu-as --with-gnu-ld --with-specs='%{funwind-tables|fno-unwind-tables|mabi=*|ffreestanding|nostdlib:;:-funwind-tables} %{O2:%{!fno-remove-local-statics: -fremove-local-statics}} %{O*:%{O|O0|O1|O2|Os:;:%{!fno-remove-local-statics: -fremove-local-statics}}}' --enable-languages=c,c++ --enable-shared --disable-lto --enable-symvers=gnu --enable-__cxa_atexit --with-pkgversion='Sourcery G++ Lite 2010q1-202' --with-bugurl=https://support.codesourcery.com/GNUToolchain/ --disable-nls --prefix=/opt/codesourcery --with-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc --with-build-sysroot=/scratch/julian/2010q1-release-linux-lite/install/arm-none-linux-gnueabi/libc --with-gmp=/scratch/julian/2010q1-release-linux-lite/obj/host-libs-2010q1-202-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-mpfr=/scratch/julian/2010q1-release-linux-lite/obj/host-libs-2010q1-202-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-ppl=/scratch/julian/2010q1-release-linux-lite/obj/host-libs-2010q1-202-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-cloog=/scratch/julian/2010q1-release-linux-lite/obj/host-libs-2010q1-202-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --disable-libgomp --enable-poison-system-directories --with-build-time-tools=/scratch/julian/2010q1-release-linux-lite/install/arm-none-linux-gnueabi/bin --with-build-time-tools=/scratch/julian/2010q1-release-linux-lite/install/arm-none-linux-gnueabi/bin Thread model: posix gcc version 4.4.1 (Sourcery G++ Lite 2010q1-202) COLLECT_GCC_OPTIONS='-L/usr/arm-unknown-linux-gnueabi/usr/lib' '-v' '-march=armv5te' '-funwind-tables' /opt/codesourcery/libexec/gcc/arm-none-linux-gnueabi/4.4.1/cc1 -quiet -v test.c -quiet -dumpbase test.c -march=armv5te -auxbase test -version -funwind-tables -o /tmp/ccaDSo09.s ignoring nonexistent directory "/opt/codesourcery/arm-none-linux-gnueabi/libc/usr/local/include" #include "..." search starts here: #include search starts here: /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/include /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/include-fixed /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/include /opt/codesourcery/arm-none-linux-gnueabi/libc/usr/include End of search list. GNU C (Sourcery G++ Lite 2010q1-202) version 4.4.1 (arm-none-linux-gnueabi) compiled by GNU C version 4.3.2, GMP version 4.3.1, MPFR version 2.4.2. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 250bf78701f747da89e730786c466148 COLLECT_GCC_OPTIONS='-L/usr/arm-unknown-linux-gnueabi/usr/lib' '-v' '-march=armv5te' '-funwind-tables' /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/as -v -march=armv5te -meabi=5 -o /tmp/ccQTJKJd.o /tmp/ccaDSo09.s GNU assembler version 2.19.51 (arm-none-linux-gnueabi) using BFD version (Sourcery G++ Lite 2010q1-202) 2.19.51.20090709 COMPILER_PATH=/opt/codesourcery/libexec/gcc/arm-none-linux-gnueabi/4.4.1/:/opt/codesourcery/libexec/gcc/arm-none-linux-gnueabi/4.4.1/:/opt/codesourcery/libexec/gcc/arm-none-linux-gnueabi/:/opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/:/opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/:/opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ LIBRARY_PATH=/opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/:/opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/lib/:/opt/codesourcery/arm-none-linux-gnueabi/libc/lib/:/opt/codesourcery/arm-none-linux-gnueabi/libc/usr/lib/ COLLECT_GCC_OPTIONS='-L/usr/arm-unknown-linux-gnueabi/usr/lib' '-v' '-march=armv5te' '-funwind-tables' /opt/codesourcery/libexec/gcc/arm-none-linux-gnueabi/4.4.1/collect2 --sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc --eh-frame-hdr -dynamic-linker /lib/ld-linux.so.3 -X -m armelf_linux_eabi /opt/codesourcery/arm-none-linux-gnueabi/libc/usr/lib/crt1.o /opt/codesourcery/arm-none-linux-gnueabi/libc/usr/lib/crti.o /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/crtbegin.o -L/usr/arm-unknown-linux-gnueabi/usr/lib -L/opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1 -L/opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/lib -L/opt/codesourcery/arm-none-linux-gnueabi/libc/lib -L/opt/codesourcery/arm-none-linux-gnueabi/libc/usr/lib /tmp/ccQTJKJd.o -verbose -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/crtend.o /opt/codesourcery/arm-none-linux-gnueabi/libc/usr/lib/crtn.o GNU ld (Sourcery G++ Lite 2010q1-202) 2.19.51.20090709 Supported emulations: armelf_linux_eabi armelfb_linux_eabi using internal linker script: ================================================== /* Script for -z combreloc: combine and sort reloc sections */ OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") OUTPUT_ARCH(arm) ENTRY(_start) SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib"); SECTIONS { /* Read-only sections, merged into text segment: */ PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x00008000)); . = SEGMENT_START("text-segment", 0x00008000) + SIZEOF_HEADERS; .interp : { *(.interp) } .note.gnu.build-id : { *(.note.gnu.build-id) } .hash : { *(.hash) } .gnu.hash : { *(.gnu.hash) } .dynsym : { *(.dynsym) } .dynstr : { *(.dynstr) } .gnu.version : { *(.gnu.version) } .gnu.version_d : { *(.gnu.version_d) } .gnu.version_r : { *(.gnu.version_r) } .rel.dyn : { *(.rel.init) *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) *(.rel.fini) *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*) *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) *(.rel.ctors) *(.rel.dtors) *(.rel.got) *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) *(.rel.ifunc) } .rela.dyn : { *(.rela.init) *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) *(.rela.fini) *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) *(.rela.ctors) *(.rela.dtors) *(.rela.got) *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) *(.rela.ifunc) } .rel.plt : { *(.rel.plt) PROVIDE_HIDDEN (__rel_iplt_start = .); *(.rel.iplt) PROVIDE_HIDDEN (__rel_iplt_end = .); } .rela.plt : { *(.rela.plt) PROVIDE_HIDDEN (__rela_iplt_start = .); *(.rela.iplt) PROVIDE_HIDDEN (__rela_iplt_end = .); } .init : { KEEP (*(.init)) } =0 .plt : { *(.plt) *(.iplt)} .text : { *(.text .stub .text.* .gnu.linkonce.t.*) /* .gnu.warning sections are handled specially by elf32.em. */ *(.gnu.warning) *(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx) } =0 .fini : { KEEP (*(.fini)) } =0 PROVIDE (__etext = .); PROVIDE (_etext = .); PROVIDE (etext = .); .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } .rodata1 : { *(.rodata1) } .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } PROVIDE_HIDDEN (__exidx_start = .); .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } PROVIDE_HIDDEN (__exidx_end = .); .eh_frame_hdr : { *(.eh_frame_hdr) } .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } /* Adjust the address for the data segment. We want to adjust up to the same address within the page on the next page up. */ . = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); /* Exception handling */ .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) } .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } /* Thread Local Storage sections */ .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } .preinit_array : { PROVIDE_HIDDEN (__preinit_array_start = .); KEEP (*(.preinit_array)) PROVIDE_HIDDEN (__preinit_array_end = .); } .init_array : { PROVIDE_HIDDEN (__init_array_start = .); KEEP (*(SORT(.init_array.*))) KEEP (*(.init_array)) PROVIDE_HIDDEN (__init_array_end = .); } .fini_array : { PROVIDE_HIDDEN (__fini_array_start = .); KEEP (*(SORT(.fini_array.*))) KEEP (*(.fini_array)) PROVIDE_HIDDEN (__fini_array_end = .); } .ctors : { /* gcc uses crtbegin.o to find the start of the constructors, so we make sure it is first. Because this is a wildcard, it doesn't matter if the user does not actually link against crtbegin.o; the linker won't look for a file to match a wildcard. The wildcard also means that it doesn't matter which directory crtbegin.o is in. */ KEEP (*crtbegin.o(.ctors)) KEEP (*crtbegin?.o(.ctors)) /* We don't want to include the .ctor section from the crtend.o file until after the sorted ctors. The .ctor section from the crtend file contains the end of ctors marker and it must be last */ KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) KEEP (*(SORT(.ctors.*))) KEEP (*(.ctors)) } .dtors : { KEEP (*crtbegin.o(.dtors)) KEEP (*crtbegin?.o(.dtors)) KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) KEEP (*(SORT(.dtors.*))) KEEP (*(.dtors)) } .jcr : { KEEP (*(.jcr)) } .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) } .dynamic : { *(.dynamic) } . = DATA_SEGMENT_RELRO_END (0, .); .got : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) } .data : { __data_start = . ; *(.data .data.* .gnu.linkonce.d.*) SORT(CONSTRUCTORS) } .data1 : { *(.data1) } _edata = .; PROVIDE (edata = .); __bss_start = .; __bss_start__ = .; .bss : { *(.dynbss) *(.bss .bss.* .gnu.linkonce.b.*) *(COMMON) /* Align here to ensure that the .bss section occupies space up to _end. Align after .bss to ensure correct alignment even if the .bss section disappears because there are no input sections. FIXME: Why do we need it? When there is no .bss section, we don't pad the .data section. */ . = ALIGN(. != 0 ? 32 / 8 : 1); } _bss_end__ = . ; __bss_end__ = . ; . = ALIGN(32 / 8); . = ALIGN(32 / 8); __end__ = . ; _end = .; PROVIDE (end = .); . = DATA_SEGMENT_END (.); /* Stabs debugging sections. */ .stab 0 : { *(.stab) } .stabstr 0 : { *(.stabstr) } .stab.excl 0 : { *(.stab.excl) } .stab.exclstr 0 : { *(.stab.exclstr) } .stab.index 0 : { *(.stab.index) } .stab.indexstr 0 : { *(.stab.indexstr) } .comment 0 : { *(.comment) } /* DWARF debug sections. Symbols in the DWARF debugging sections are relative to the beginning of the section so we begin them at 0. */ /* DWARF 1 */ .debug 0 : { *(.debug) } .line 0 : { *(.line) } /* GNU DWARF 1 extensions */ .debug_srcinfo 0 : { *(.debug_srcinfo) } .debug_sfnames 0 : { *(.debug_sfnames) } /* DWARF 1.1 and DWARF 2 */ .debug_aranges 0 : { *(.debug_aranges) } .debug_pubnames 0 : { *(.debug_pubnames) } /* DWARF 2 */ .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } .debug_abbrev 0 : { *(.debug_abbrev) } .debug_line 0 : { *(.debug_line) } .debug_frame 0 : { *(.debug_frame) } .debug_str 0 : { *(.debug_str) } .debug_loc 0 : { *(.debug_loc) } .debug_macinfo 0 : { *(.debug_macinfo) } /* SGI/MIPS DWARF 2 extensions */ .debug_weaknames 0 : { *(.debug_weaknames) } .debug_funcnames 0 : { *(.debug_funcnames) } .debug_typenames 0 : { *(.debug_typenames) } .debug_varnames 0 : { *(.debug_varnames) } /* DWARF 3 */ .debug_pubtypes 0 : { *(.debug_pubtypes) } .debug_ranges 0 : { *(.debug_ranges) } .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) } .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) } /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) } } ================================================== attempt to open /opt/codesourcery/arm-none-linux-gnueabi/libc/usr/lib/crt1.o succeeded /opt/codesourcery/arm-none-linux-gnueabi/libc/usr/lib/crt1.o attempt to open /opt/codesourcery/arm-none-linux-gnueabi/libc/usr/lib/crti.o succeeded /opt/codesourcery/arm-none-linux-gnueabi/libc/usr/lib/crti.o attempt to open /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/crtbegin.o succeeded /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/crtbegin.o attempt to open /tmp/ccQTJKJd.o succeeded /tmp/ccQTJKJd.o attempt to open /usr/arm-unknown-linux-gnueabi/usr/lib/libgcc.so failed attempt to open /usr/arm-unknown-linux-gnueabi/usr/lib/libgcc.a failed attempt to open /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/libgcc.so failed attempt to open /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/libgcc.a succeeded attempt to open /usr/arm-unknown-linux-gnueabi/usr/lib/libgcc_s.so failed attempt to open /usr/arm-unknown-linux-gnueabi/usr/lib/libgcc_s.a failed attempt to open /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/libgcc_s.so failed attempt to open /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/libgcc_s.a failed attempt to open /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/lib/libgcc_s.so failed attempt to open /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/lib/libgcc_s.a failed attempt to open /opt/codesourcery/arm-none-linux-gnueabi/libc/lib/libgcc_s.so succeeded -lgcc_s (/opt/codesourcery/arm-none-linux-gnueabi/libc/lib/libgcc_s.so) attempt to open /usr/arm-unknown-linux-gnueabi/usr/lib/libc.so succeeded opened script file /usr/arm-unknown-linux-gnueabi/usr/lib/libc.so opened script file /usr/arm-unknown-linux-gnueabi/usr/lib/libc.so attempt to open /lib/libc.so.6 succeeded opened script file /lib/libc.so.6 /lib/libc.so.6: file not recognized: File format not recognized collect2: ld returned 1 exit status
2 个解决方案
#1
12
Your cross-compiling glibc is configured in a wrong way.
您的交叉编译glibc配置错误。
In -Wl,-verbose
linker says:
在- wl - verbose链接器说:
attempt to open /usr/arm-unknown-linux-gnueabi/usr/lib/libc.so succeeded
opened script file /usr/arm-unknown-linux-gnueabi/usr/lib/libc.so
So, it used your -L
option and was able to open libc.so. But this is not a real .so
dynamic library, it is a script (linker script).
所以,它使用了你的-L选项并且能够打开libc.so。但这不是一个真实的动态库,它是一个脚本(链接脚本)。
Telepathic mode on: Last line of this libc.so
script is
心灵感应模式:这个libc的最后一行。所以脚本
GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a AS_NEEDED ( /lib/ld-linux.so.3 ) )
Telepathic mode off
心灵感应模式了
This line contains absolute pathes hardcoded and redirects linker from arm-...abi to the system's libc ignoring most of search-dirs (may be there is some secret option of ld
).
这条线包含绝对路径硬编码和重定向连接器。abi对系统的libc忽略了大部分的搜索引擎(可能有ld的秘密选项)。
Just edit this file (with doing a backup) with any text editor and replace all /lib
with /usr/arm-unknown-linux-gnueabi/lib
. (My good cross-compiler environment has all pathes in this script replaced with prefix.)
只需编辑这个文件(与做备份),使用任何文本编辑器,并将所有/lib替换为/usr/arm-未知-linux-gnueabi/lib。(我良好的交叉编译器环境在这个脚本中有所有的路径替换为前缀。)
The original script should be used on native compile, native run, but not on cross compiling.
原始的脚本应该用于本机编译,本机运行,但不用于交叉编译。
UPDATE: bytesex says http://linux.bytesex.org/cross-compiler.html that there is the same problem with /usr/lib/libpthread.so
, do the replace in this file too.
更新:bytesex说:http://linux.bytesex.org/cross- .html,与/usr/lib/libpthread有相同的问题。所以,在这个文件中也做替换。
To check other libs, do file -skL *.so|grep text
in the lib dir.
检查其他libs,做file -skL *。在lib目录中,|grep文本。
#2
6
As explained by @osgx, gcc is looking in the wrong path for its libraries. I hit a similar issue when trying to cross-compile a program for arm on x86_64. As editing the root-owned files was not an option, I searched further and discovered the --sysroot
option:
正如@osgx所解释的,gcc正在为它的库寻找错误的路径。当我试图在x86_64上交叉编译一个程序时,我遇到了一个类似的问题。由于编辑root用户的文件不是一个选项,我进一步搜索并发现了——sysroot选项:
--sysroot=dir
Use dir as the logical root directory for headers and libraries. For example, if the compiler normally searches for headers in /usr/include and libraries in /usr/lib, it instead searches dir/usr/include and dir/usr/lib.——sysroot=dir使用dir作为标题和库的逻辑根目录。例如,如果编译器通常在/usr/lib中搜索标题,那么它将搜索dir/usr/include和dir/usr/lib。
If you use both this option and the -isysroot option, then the --sysroot option applies to libraries, but the -isysroot option applies to header files.
如果您同时使用这个选项和-isysroot选项,那么——sysroot选项适用于库,但是-isysroot选项适用于头文件。
The GNU linker (beginning with version 2.16) has the necessary support for this option. If your linker does not support this option, the header file aspect of --sysroot still works, but the library aspect does not.
GNU链接器(从版本2.16开始)对这个选项有必要的支持。如果您的链接器不支持此选项,则-sysroot的头文件方面仍然有效,但是库方面没有。
Example usage:
使用示例:
./configure --host=arm-unknown-linux-gnueabi \
CFLAGS='-g -O2 --sysroot=/tmp/rpi-root'
#1
12
Your cross-compiling glibc is configured in a wrong way.
您的交叉编译glibc配置错误。
In -Wl,-verbose
linker says:
在- wl - verbose链接器说:
attempt to open /usr/arm-unknown-linux-gnueabi/usr/lib/libc.so succeeded
opened script file /usr/arm-unknown-linux-gnueabi/usr/lib/libc.so
So, it used your -L
option and was able to open libc.so. But this is not a real .so
dynamic library, it is a script (linker script).
所以,它使用了你的-L选项并且能够打开libc.so。但这不是一个真实的动态库,它是一个脚本(链接脚本)。
Telepathic mode on: Last line of this libc.so
script is
心灵感应模式:这个libc的最后一行。所以脚本
GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a AS_NEEDED ( /lib/ld-linux.so.3 ) )
Telepathic mode off
心灵感应模式了
This line contains absolute pathes hardcoded and redirects linker from arm-...abi to the system's libc ignoring most of search-dirs (may be there is some secret option of ld
).
这条线包含绝对路径硬编码和重定向连接器。abi对系统的libc忽略了大部分的搜索引擎(可能有ld的秘密选项)。
Just edit this file (with doing a backup) with any text editor and replace all /lib
with /usr/arm-unknown-linux-gnueabi/lib
. (My good cross-compiler environment has all pathes in this script replaced with prefix.)
只需编辑这个文件(与做备份),使用任何文本编辑器,并将所有/lib替换为/usr/arm-未知-linux-gnueabi/lib。(我良好的交叉编译器环境在这个脚本中有所有的路径替换为前缀。)
The original script should be used on native compile, native run, but not on cross compiling.
原始的脚本应该用于本机编译,本机运行,但不用于交叉编译。
UPDATE: bytesex says http://linux.bytesex.org/cross-compiler.html that there is the same problem with /usr/lib/libpthread.so
, do the replace in this file too.
更新:bytesex说:http://linux.bytesex.org/cross- .html,与/usr/lib/libpthread有相同的问题。所以,在这个文件中也做替换。
To check other libs, do file -skL *.so|grep text
in the lib dir.
检查其他libs,做file -skL *。在lib目录中,|grep文本。
#2
6
As explained by @osgx, gcc is looking in the wrong path for its libraries. I hit a similar issue when trying to cross-compile a program for arm on x86_64. As editing the root-owned files was not an option, I searched further and discovered the --sysroot
option:
正如@osgx所解释的,gcc正在为它的库寻找错误的路径。当我试图在x86_64上交叉编译一个程序时,我遇到了一个类似的问题。由于编辑root用户的文件不是一个选项,我进一步搜索并发现了——sysroot选项:
--sysroot=dir
Use dir as the logical root directory for headers and libraries. For example, if the compiler normally searches for headers in /usr/include and libraries in /usr/lib, it instead searches dir/usr/include and dir/usr/lib.——sysroot=dir使用dir作为标题和库的逻辑根目录。例如,如果编译器通常在/usr/lib中搜索标题,那么它将搜索dir/usr/include和dir/usr/lib。
If you use both this option and the -isysroot option, then the --sysroot option applies to libraries, but the -isysroot option applies to header files.
如果您同时使用这个选项和-isysroot选项,那么——sysroot选项适用于库,但是-isysroot选项适用于头文件。
The GNU linker (beginning with version 2.16) has the necessary support for this option. If your linker does not support this option, the header file aspect of --sysroot still works, but the library aspect does not.
GNU链接器(从版本2.16开始)对这个选项有必要的支持。如果您的链接器不支持此选项,则-sysroot的头文件方面仍然有效,但是库方面没有。
Example usage:
使用示例:
./configure --host=arm-unknown-linux-gnueabi \
CFLAGS='-g -O2 --sysroot=/tmp/rpi-root'