linux 用ld链接nasm编译的elf格式的.o文件报错

编译命令:

nasm -f elf hello.asm -o hello.o

ld -s hello.o -o hello

报错信息:

ld: i386 architecture of input file `hello.o' is incompatible with i386:x86-64 output


解决方法:

命令行输入:>ld -m elf

                        ld: unrecognised emulation mode: elf
                        Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 i386linux elf_l1om elf_k1om i386pep i386pe

根据输出选择对应的架构选项,将链接命令修改为:ld -m elf_i386 -s -o hello hello.o


如果需要链接gcc编的.o文件,则gcc编译命令需要加上-m32参数,如:gcc -m32 -c -o bar.o bar.c


详见:

http://www.linuxquestions.org/questions/programming-9/assembly-error-i386-architecture-incompatible-with-i386-x86-64-output-827609/

http://www.ithao123.cn/content-5258444.html

发布了8 篇原创文章 · 获赞 0 · 访问量 5011
展开阅读全文

arm-linux-androideabi-gcc 交叉编译报错

07-21

对Linux下的一个开源代码进行交叉编译,准备移植到Android平台上。但是一直报错。 编辑脚本如下: export NDKROOT="/home/bupt/android-ndk-r9d" export PREBUILT=$NDKROOT/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64 export SYSROOT=$NDKROOT/platforms/android-18/arch-arm export CC=$PREBUILT/bin/arm-linux-androideabi-gcc export LD=$PREBUILT/bin/arm-linux-androideabi-ld export AS=$PREBUILT/bin/arm-linux-androideabi-gcc export AR=$PREBUILT/bin/arm-linux-androideabi-ar export RANLIB=$PREBUILT/bin/arm-linux-androideabi-ranlib export STRIP=$PREBUILT/bin/arm-linux-androideabi-strip CFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-arm -fPIC -DX264_VERSION -DANDROID -DHAVE_PTHREAD -D__ARM_ARCH_7__ -D__ARM_ARCH_7A__ -march=armv7-a -fomit-frame-pointer -mfloat-abi=softfp -mfpu=neon -I$TOOLCHAINS_INCLUDE -I$NDKROOT/platforms/android-18/arch-arm/usr/include" export CFLAGS LDFLAGS="-Wl,-T,$PREBUILT/arm-linux-androideabi/lib/ldscripts/armelf_linux_eabi.x -Wl,-rpath-link=$NDKROOT/platforms/android-18/arch-arm/usr/lib -L$NDKROOT/platforms/android-18/arch-arm/usr/lib -nostdlib -lc -lm -ldl -lgcc" export LDFLAGS ./configure --prefix=/home/bupt/clamav/clamav-0.98.4/clamav-android --host=arm-linux-androideabi --with-openssl=/usr/lib config.log报错如下: configure:3820: /home/bupt/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -V >&5 arm-linux-androideabi-gcc: error: unrecognized option '-V' arm-linux-androideabi-gcc: fatal error: no input files compilation terminated. configure:3831: $? = 1 configure:3820: /home/bupt/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -qversion >&5 arm-linux-androideabi-gcc: error: unrecognized option '-qversion' arm-linux-androideabi-gcc: fatal error: no input files compilation terminated. ================================== home/bupt/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/include-fixed/limits.h:169:61: error: no include path in which to search for limits.h configure:4461: $? = 1 但是在这个文件夹下可以找到这个.h文件。 conftest.c:13:0: fatal error: assert.h: No such file or directory compilation terminated. 其他报错信息都是以上这种找不到头文件等。 =========================== 命令行报错为: configure: ****** mempool support disabled (mmap not available or not usable) checking for ld used by GCC... /home/bupt/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld checking if the linker (/home/bupt/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld) is GNU ld... yes checking for shared library run path origin... done checking check.h usability... no checking check.h presence... no checking for check.h... no configure: unable to compile/link with check checking for libxml2 installation... not found configure: ****** libxml2 support unavailable checking for OpenSSL installation... configure: error: OpenSSL not found. 求解决方案!!!!!!!!!!!!!! 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览