简体   繁体   English

链接问题:i386:x86-64输入文件架构* .o与i386输出不兼容

[英]linking problem: i386:x86-64 architecture of input file *.o is incompatible with i386 output

I got a problem in linking when I moved my osdev to linux where it worked previously on gcc 3.5.* and binutils 2.18 (compiled to output x86_64-elf) running under cygwin. 当我将我的osdev移动到Linux时,我遇到了一个问题,它之前在gcc 3.5。*和binutils 2.18(编译为输出x86_64-elf)上运行在cygwin下运行。

Here are the infos: 以下是信息:

gcc -v gcc -v


Using built-in specs.
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5) 



ld -v ld -v


GNU ld (GNU Binutils for Ubuntu) 2.20.51-system.20100908


part of ld -help ld -help的一部分


....
ld: supported targets: elf32-i386 a.out-i386-linux pei-i386 elf32-little elf32-big elf64-x86-64 pei-x86-64 elf64-l1om elf64-little elf64-big plugin srec symbolsrec verilog tekhex binary ihex trad-core
....




The code: 编码:

main.c main.c中
\nvoid main(){ 
/**some code here**/
}


start.asm start.asm
\n[bits 64] 
global start
extern main
start:
call main


link.ld link.ld
 OUTPUT_FORMAT(elf64-x86-64); 
offset = 0x1000000;
ENTRY(start);
SECTIONS{
. = offset;
.text : AT(ADDR(.text) - offset){
_code = .;
*(.text)
(.rodata )
. = ALIGN(4096);}
.data : AT(ADDR(.data) - offset){
_data = .;
*(.data)
. = ALIGN(4096);}
.bss : AT(ADDR(.bss) - offset){
_bss = .;
*(.bss)
*(COMMON)
. = ALIGN(4096);}
_end = .;
/DISCARD/ :
{*(.comment)}
}


build.sh build.sh
 nasm -f elf64 -o start.o start.asm 
echo .
echo .
echo .
gcc -m64 -ffreestanding -nostdlib -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow -c -o main.o main.c
echo .
echo .
echo .
ld -nostdlib -nodefaultlibs -T link.ld -o out.elf start.o main.o



terminal output 终端输出
 . 
.
.
.
.
.
ld: i386:x86-64 architecture of input file 'start.o' is incompatible with i386 output
ld: i386:x86-64 architecture of input file 'main.o' is incompatible with i386 output


I don't understand why it displays 'incompatible with i386 output' when there's OUTPUT_FORMAT(elf64-x86-64); 当有OUTPUT_FORMAT(elf64-x86-64)时,我不明白为什么它显示“与i386输出不兼容”; in my linker script specifying the targeted output.. 在我的链接器脚本中指定目标输出..

Try this: 尝试这个:

LDEMULATION="elf_x86_64"
ld -nostdlib -nodefaultlibs -T link.ld -o out.elf start.o main.o

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

相关问题 GCC:输入文件“ ../window.ui.o”的i386体系结构与i386:x86-64输出不兼容 - GCC: i386 architecture of input file `../window.ui.o' is incompatible with i386:x86-64 output CMake; 386:x86-64 输入文件架构 (..) 与 i386 不兼容 output - CMake; 386:x86-64 architecture of input file (.. ) is incompatible with i386 output c ) 出错和链接问题:输入文件的 i386:x86-64 架构,与 i386 不兼容 output - c )make error& link problem: i386:x86-64 architecture of input file, incompatible with i386 output 文件是为i386构建的,而不是在Mac OSX 10.6上为iOS 4.2编译OpenCV2.2时所链接的架构(x86_64) - file was built for i386 which is not the architecture being linked (x86_64) while compiling OpenCV2.2 for iOS 4.2 on Mac OSX 10.6 GNU链接器和体系结构i386 - GNU Linker and architecture i386 从i386移动到x86_64时的浮点精度 - Floating-point precision when moving from i386 to x86_64 C sscanf i386 与 x86_64 解析引用字符串的不同行为 - C different behavior of sscanf i386 vs x86_64 parsing quoted string timer_create在i386系统上导致分段错误,但在x86_64系统上未引起分段错误(linux) - timer_create causing segmentation fault on i386 system, but not x86_64 system(linux) 为i386编译x264 - Compiling x264 for i386 将eCos移植到i386 - Porting eCos to i386
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM