enter code here
------------
使用intel-core i7处理器 已安装UBUNTU 13.10
我的程序生成二进制文件:test 它链接到一个共享库:libtest.so libtest.so与libc.so.6链接
尝试运行二进制文件./test
时出现以下错误:
bash: ./test: cannot execute binary file
我尝试使用-m32
编译,确保了libtest.so并测试了所有内容
是32位架构并与libc.so.6 =>链接/lib/i386-linux-gnu/libc.so.6(0xf756f000)
我仍然遇到同样的错误:
bash: ./test: cannot execute binary file
我无法在x86机器上运行64位或32位二进制文件。 我不明白还有什么不对。任何指针都会有所帮助 谢谢。
我应该安装i386-linux-gnu gcc编译器吗?
以下是我机器中的gcc
./usr/bin/gcc
./usr/lib/gcc
./usr/share/bash-completion/completions/gcc
./usr/share/doc/gcc-4.8-base/gcc
./usr/share/doc/gcc
./usr/share/doc/gcc-4.7-base/gcc
./usr/libexec/gcc
:/usr/bin# objdump -f gcc
gcc: file format elf64-x86-64
architecture: i386:x86-64, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x0000000000405ee8
/usr/lib/gcc# ls
i586-mingw32msvc i686-linux-gnu x86_64-linux-gnu
/usr/libexec/gcc# ls
i586-mingw32msvc
/usr/bin# objdump -f ld
ld: file format elf64-x86-64
architecture: i386:x86-64, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x0000000000405b3c
编辑:抱歉,复制粘贴贴错线
实际错误行如下:
bash: ./test: cannot execute binary file
src/Makefile :
CC = gcc -m32
ROOT_DIR = .
SUB_DIRS = ./testlib
CPP_NAME = test
LFLAGS = -fPIC
CFLAGS = -m32 -Wall -shared
$(ROOT_DIR)/%.o : %.c
-@mkdir -p $(ROOT_DIR)/$(dir $<)
@$(CC) $(LFLAGS) $(INCPATH) $(LIBPATH) $(LDLIBS) -o $@ -c $<
EXE = $(ROOT_DIR)/$(CPP_NAME)
$(EXE): $(OBJS)
$(CC) $(LFLAGS) $(CFLAGS) $(LIBPATH) $^ $(LDLIBS) -o $@
src/testlib/Makefile:
CC = gcc -m32
CPP_NAME = test
LIB_NAME = lib$(CPP_NAME).so
ROOT_DIR = .
LIB_DIR = testlib
OBJS = $(addprefix $(ROOT_DIR)/, $(SRCS:.c=.o))
CFLAGS+= -fPIC
LFLAGS += -shared
$(LIB_DIR)/%.o : %.c
-@mkdir -p $(ROOT_DIR)/$(dir $<)
@$(CC) $(CFLAGS) $(INCPATH) -o $@ -c $<
SH_OBJ= $(LIB_DIR)/$(LIB_NAME)
$(SH_OBJ): $(OBJS)
$(CC) $(CFLAGS) $(LFLAGS) $^ -o $(LIB_NAME)