设置全局gcc默认搜索路径

设置全局gcc默认搜索路径

本文介绍了设置全局gcc默认搜索路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 运行时 arm-none-linux-gnueabi-gcc -print-search-dirs | grep库| sed's /:/ \ n / g' 我得到以下输出: 库 = / 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 以及已经列出的路径。我不在寻找代码资源的具体答案,因为我有几个可以使用的工具链。 对于那些好奇的人,这里是代码资源安装的错误: arm-none-linux-gnueabi-gcc test.c works arm-none-linux-gnueabi-gcc -L / usr / arm-unknown-linux-gnueabi / usr / lib test.c 失败: /lib/libc.so.6:文件未被识别:文件格式未被识别 collect2:ld已返回1退出状态 显然它是从主机中获取libc。我见过这种情况发生在多个工具链上,但不是全部。 回应评论: 这是 arm-none-linux-gnueabi-gcc -L / usr / arm-unknown-linux-gnueabi / usr / lib test.c -v -Wl,-verbose 使用内置规格。 目标:arm-none-linux-gnueabi 配置为:/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 / ar m-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 线程模型:posix gcc版本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 忽略不存在的目录/ opt / codesourcery / arm-none-linux-gnueabi / libc / usr / local / include #include...搜索从这里开始: #include从这里开始搜索: / 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 搜索列表结束。 GNU C(Sourcery G ++ Lite 2010q1-202)版本4.4.1(arm-none-linux-gnueabi)由GNU C版本4.3.2编译,GMP版本4.3.1,MPFR版本2.4。 2。 GGC启发式:--param ggc-min-expand = 100 --param ggc-min-heapsize = 131072 编译器可执行校验和: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汇编程序版本2.19.51(arm-none-linux-gnueabi)使用BFD版本(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 /臂-NONE-Linux的gnueabi / 4.4.1 /中:/ opt / CodeSourcery的/的libexec / GCC /臂-NONE-Linux的gnueabi /:/选择/ CodeSourcery的/ LIB / GCC /臂-NONE-Linux的gnueabi / 4.4.1 /中:/ opt / CodeSourcery的/ LIB / GCC /臂-NONE-Linux的gnueabi /中:/ opt / CodeSourcery的/ LIB / GCC /掰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 支持的仿真: armelf_linux_eabi armelfb_linux_eabi 使用内部链接脚本: ================================================= = / *脚本为-z combreloc:合并和排序reloc部分* / 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 { / *只读部分,合并到文本段中:* / 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.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部分由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。*) } / *调整数据段的地址。我们希望在下一页的页面内调整最多的地址。 * / 。 = ALIGN(CONSTANT(MAXPAGESIZE)) - ((CONSTANT(MAXPAGESIZE) - 。)&(CONSTANT(MAXPAGESIZE) - 1)); 。 = DATA_SEGMENT_ALIGN(CONSTANT(MAXPAGESIZE),CONSTANT(COMMONPAGESIZE)); / *异常处理* / .eh_frame:ONLY_IF_RW {KEEP(*(。eh_frame))} .gcc_except_table:ONLY_IF_RW {*(.gcc_except_table .gcc_except_table。*)} / *线程本地存储部分* / .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使用crtbegin.o来查找的构造函数的开始,所以我们确保它是第一。因为这是一个通配符,所以无关紧要,如果用户不实际上链接到crtbegin.o; 链接器不会查找与通配符匹配的文件。通配符还意味着它与哪个目录crtbegin.o 不在同一个目录。* / KEEP(* crtbegin.o(.ctors)) KEEP(* crtbegin?.o(.ctors)) / *我们不希望在crtend.o文件中包含中的.ctor部分,直到排序的ctors之后。 crtend文件中的.ctor节包含ctors标记的结尾,它必须是最后一个* / 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))} .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 =。;提供(edata =。); __bss_start =。; __bss_start__ =。; .bss: { *(。dynbss) *(。bss .bss。* .gnu.linkonce.b。*) *(COMMON) / *在此处对齐以确保.bss部分占用高达 _end的空间。即使 .bss部分因为没有输入部分而消失,也要保持正确的对齐。 FIXME:我们为什么需要它?当没有.bss部分时,我们不会填充.data部分。 * / 。 = ALIGN(。!= 0?32/8:1); } _bss_end__ =。 ; __bss_end__ =。 ; 。 = ALIGN(32/8); 。 = ALIGN(32/8); __end__ =。 ; _end =。; PROVIDE(end =。); 。 = DATA_SEGMENT_END(。); / *插入调试部分。 * / .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调试部分。 DWARF调试部分中的符号相对于该部分的开始,因此我们以0开始。* / / * DWARF 1 * / .debug 0:{ *(。debug)} .line 0:{*(。line)} / * GNU DWARF 1扩展* / .debug_srcinfo 0:{*(。debug_srcinfo)} .debug_sfnames 0:{*(。debug_sfnames)} / * DWARF 1.1和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扩展* / .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)} } ================================== ================ 尝试打开/opt/codesourcery/arm-none-linux-gnueabi/libc/usr/lib/crt1.o成功 /opt/codesourcery/arm-none-linux-gnueabi/libc/usr/lib/crt1.o 尝试打开/ opt / codesourcery / arm-none-linux-gnueabi / libc / usr / lib / crti。 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成功 /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/crtbegin.o 尝试打开/ tm p / ccQTJKJd.o成功 /tmp/ccQTJKJd.o 尝试打开/usr/arm-unknown-linux-gnueabi/usr/lib/libgcc.so失败尝试打开/ usr / arm-unknown-linux-gnueabi / usr / lib / libgcc.a失败尝试打开/opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/libgcc.so失败尝试打开/opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/libgcc.a成功尝试打开/ usr / arm-unknown-linux-gnueabi / usr / lib / libgcc_s.so失败尝试打开/usr/arm-unknown-linux-gnueabi/usr/lib/libgcc_s.a失败尝试打开/ opt / codesourcery / lib / gcc / arm-none-linux-gnueabi / 4.4.1 / libgcc_s.so失败尝试打开/opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/libgcc_s.a失败尝试打开/opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/lib/libgcc_s。因此失败尝试打开/opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/ lib / libgcc_s.a失败尝试打开/opt/codesourcery/arm-none-linux-gnueabi/libc/lib/libgcc_s.so成功 -lgcc_s(/ opt / codesourcery / arm-none-linux-gnueabi / libc / lib / libgcc_s.so)尝试打开/usr/arm-unknown-linux-gnueabi/usr/lib/libc.so成功打开脚本文件/ usr / arm-unknown-linux-gnueabi / usr / lib / libc.so 打开脚本文件/usr/arm-unknown-linux-gnueabi/usr/lib/libc.so 尝试打开/lib/libc.so.6成功打开的脚本文件/lib/libc.so.6 /lib/libc.so.6:文件未识别:文件格式未识别 collect2:ld返回1退出状态 解决方案您的交叉编译glibc配置错误。 -Wl,-verbose linker说: 尝试打开/usr/arm-unknown-linux-gnueabi/usr/lib/libc.so成功打开的脚本文件/usr/arm-unknown-linux-gnueabi/usr/lib/libc.so 因此,它使用 -L o并且能够打开libc.so.但这不是一个真正的 .so 动态库,它是一个脚本(链接器脚本)。 传感器模式on: libc.so 脚本的最后一行是 GROUP( /lib/libc.so.6 /usr/lib/libc_nonshared.a AS_NEEDED(/lib/ld-linux.so.3)) 传感器模式关闭 这行包含硬编码的绝对路径,并将arm -... abi中的链接程序重定向到系统的libc,而忽略大部分search-dirs(可能有一些秘密选项 ld )。 只要编辑这个文件备份),并用 / usr / arm-unknown-linux-gnueabi / lib / lib >。 (我的良好的交叉编译环境将脚本中的所有路径替换为前缀。) 原始脚本应该用于本机编译,本地运行,但不能跨编译。 更新:bytesex说 http://linux.bytesex .org / cross-compiler.html 中存在与 /usr/lib/libpthread.so 相同的问题,请在该文件中进行替换。 要检查其他库,请在lib目录下执行 file -skL * .so | grep text 。 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:/target/usr/lib/target/libin addition to the paths already listed. I'm not looking for a codesourcey specific answer, since I have several toolchains I can work with.For those who are curious, here is the error from a codesourcery installation:arm-none-linux-gnueabi-gcc test.cworksarm-none-linux-gnueabi-gcc -L/usr/arm-unknown-linux-gnueabi/usr/lib test.cfails with:/lib/libc.so.6: file not recognized: File format not recognizedcollect2: ld returned 1 exit statusso obviously it's grabbing libc from the host. I've seen this happen with more than one toolchain, but not all.In response to a comment:Here is the output forarm-none-linux-gnueabi-gcc -L/usr/arm-unknown-linux-gnueabi/usr/lib test.c -v -Wl,-verboseUsing built-in specs.Target: arm-none-linux-gnueabiConfigured 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/binThread model: posixgcc 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.signoring 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/includeEnd 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=131072Compiler executable checksum: 250bf78701f747da89e730786c466148COLLECT_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.sGNU assembler version 2.19.51 (arm-none-linux-gnueabi) using BFD version (Sourcery G++ Lite 2010q1-202) 2.19.51.20090709COMPILER_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.oGNU ld (Sourcery G++ Lite 2010q1-202) 2.19.51.20090709 Supported emulations: armelf_linux_eabi armelfb_linux_eabiusing 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.oattempt to open /opt/codesourcery/arm-none-linux-gnueabi/libc/usr/lib/crti.o succeeded/opt/codesourcery/arm-none-linux-gnueabi/libc/usr/lib/crti.oattempt 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.oattempt to open /tmp/ccQTJKJd.o succeeded/tmp/ccQTJKJd.oattempt to open /usr/arm-unknown-linux-gnueabi/usr/lib/libgcc.so failedattempt to open /usr/arm-unknown-linux-gnueabi/usr/lib/libgcc.a failedattempt to open /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/libgcc.so failedattempt to open /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/libgcc.a succeededattempt to open /usr/arm-unknown-linux-gnueabi/usr/lib/libgcc_s.so failedattempt to open /usr/arm-unknown-linux-gnueabi/usr/lib/libgcc_s.a failedattempt to open /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/libgcc_s.so failedattempt to open /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/libgcc_s.a failedattempt to open /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/lib/libgcc_s.so failedattempt to open /opt/codesourcery/lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/lib/libgcc_s.a failedattempt 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 succeededopened script file /usr/arm-unknown-linux-gnueabi/usr/lib/libc.soopened script file /usr/arm-unknown-linux-gnueabi/usr/lib/libc.soattempt to open /lib/libc.so.6 succeededopened script file /lib/libc.so.6/lib/libc.so.6: file not recognized: File format not recognizedcollect2: ld returned 1 exit status 解决方案 Your cross-compiling glibc is configured in a wrong way.In -Wl,-verbose linker says:attempt to open /usr/arm-unknown-linux-gnueabi/usr/lib/libc.so succeededopened script file /usr/arm-unknown-linux-gnueabi/usr/lib/libc.soSo, 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).Telepathic mode on: Last line of this libc.so script is GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a AS_NEEDED ( /lib/ld-linux.so.3 ) )Telepathic mode offThis 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).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.)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.To check other libs, do file -skL *.so|grep text in the lib dir. 这篇关于设置全局gcc默认搜索路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-30 23:25