设置全局gcc默认搜索路径
运行时
arm-none-linux-gnueabi-gcc -print-search-dirs | grep libraries | sed 's/:/n/g'
我得到以下输出:
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/
当交叉编译一些软件包时,它会让我的生活更容易追加到这些路径上。 我知道-L选项,我想使用它,但许多软件包在交叉编译时不尊重它,而且在代码源中使用它会导致问题。 (详见本文结尾)。 基本上我有一个完整的目录树,包含所有必需的文件来编译软件包,我想将目录树添加到默认搜索路径。 例如,这样-print-search-dirs也将输出类似于以下内容的路径:
/target/usr/lib
/target/lib
除了已经列出的路径之外。 我不在寻找代码资源的具体答案,因为我有几个可以使用的工具链。
对于那些好奇的人来说,Codeourcery安装中的错误是:
arm-none-linux-gnueabi-gcc test.c
作品
arm-none-linux-gnueabi-gcc -L/usr/arm-unknown-linux-gnueabi/usr/lib test.c
失败:
/lib/libc.so.6: file not recognized: File format not recognized
collect2: ld returned 1 exit status
所以显然它是从主机中获取libc。 我见过这种情况发生在多个工具链上,但不是全部。
在回应评论:这是输出
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
您的交叉编译glibc配置错误。
在-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
所以,它使用了-L
选项并能够打开libc.so. 但这不是一个真正的.so
动态库,它是一个脚本(链接器脚本)。
心灵感应模式开启:这个libc.so
脚本的最后一行是
GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a AS_NEEDED ( /lib/ld-linux.so.3 ) )
心灵感应模式关闭
此行包含硬编码的绝对路径,并将arm -... abi中的链接程序重定向到系统的libc,而忽略大多数搜索目录(可能存在ld
一些秘密选项)。
只需使用任何文本编辑器编辑此文件(通过执行备份),并将所有/lib
替换为/usr/arm-unknown-linux-gnueabi/lib
。 (我的良好交叉编译器环境已将此脚本中的所有路径替换为前缀。)
原始脚本应该用于本地编译,本地运行,但不能用于交叉编译。
更新:bytesex表示http://linux.bytesex.org/cross-compiler.html与/usr/lib/libpthread.so
存在相同的问题,请在该文件中进行替换。
要检查其他库,请在lib目录下执行file -skL *.so|grep text
。
正如@osgx所解释的那样,gcc正在寻找其库的错误路径。 当我尝试在x86_64上交叉编译arm的程序时,我遇到了类似的问题。 由于编辑根文件不是一个选项,我进一步搜索并发现了--sysroot
选项:
--sysroot = DIR
使用dir作为标题和库的逻辑根目录。 例如,如果编译器通常在/ usr / include中搜索头文件,并在/ usr / lib中搜索库,则它会搜索dir / usr / include和dir / usr / lib。
如果您同时使用此选项和-isysroot选项,那么--sysroot选项将应用于库,但-isysroot选项适用于头文件。
GNU链接器(从版本2.16开始)对此选项有必要的支持。 如果你的链接器不支持这个选项,--sysroot的头文件方面仍然有效,但是库方面没有。
用法示例:
./configure --host=arm-unknown-linux-gnueabi
CFLAGS='-g -O2 --sysroot=/tmp/rpi-root'
链接地址: http://www.djcxy.com/p/86909.html
上一篇: set global gcc default search paths
下一篇: In GCC, can precompiled headers be included from other headers?