![无法执行二进制文件:Exec 格式错误 - Ubuntu 16.04 + Make + GCC](https://linux22.com/image/1171198/%E6%97%A0%E6%B3%95%E6%89%A7%E8%A1%8C%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%96%87%E4%BB%B6%EF%BC%9AExec%20%E6%A0%BC%E5%BC%8F%E9%94%99%E8%AF%AF%20-%20Ubuntu%2016.04%20%2B%20Make%20%2B%20GCC.png)
我知道其他人也有类似的问题,但我的问题似乎很独特,因为我没有犯明显的错误。我已查看其他问题,并在下面列出了所有必需的详细信息。
当我尝试执行使用 make 编译的二进制文件 (swetest.o) 时出现以下错误
bash: ./swetest.o: cannot execute binary file: Exec format error
这是我的系统信息
uname -a
Linux vXXXXXX 4.4.0-141-generic #167-Ubuntu SMP Wed Dec 5 10:40:15 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
这是我的文件信息
file swetest.o
swetest.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
这是我的编译器信息
gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
这是“Makefile”
CFLAGS = -g -Wall -fPIC # for Linux and other gcc systems
OP=$(CFLAGS)
CC=gcc #for Linux
# compilation rule for general cases
.o :
$(CC) $(OP) -o $@ $? -lm
.c.o:
$(CC) -c $(OP) $<
SWEOBJ = swedate.o swehouse.o swejpl.o swemmoon.o swemplan.o swepcalc.o sweph.o\
swepdate.o swephlib.o swecl.o swehel.o
swetest: swetest.o libswe.a
$(CC) $(OP) -o swetest swetest.o -L. -lswe -lm -ldl
swemini: swemini.o libswe.a
$(CC) $(OP) -o swemini swemini.o -L. -lswe -lm
# create an archive and a dynamic link libary for SwissEph
# a user of this library will inlcude swephexp.h and link with -lswe
libswe.a: $(SWEOBJ)
ar r libswe.a $(SWEOBJ)
libswe.so: $(SWEOBJ)
$(CC) -shared -o libswe.so $(SWEOBJ)
clean:
rm -f *.o swetest libswe*
###
swecl.o: swejpl.h sweodef.h swephexp.h swedll.h sweph.h swephlib.h
sweclips.o: sweodef.h swephexp.h swedll.h
swedate.o: swephexp.h sweodef.h swedll.h
swehel.o: swephexp.h sweodef.h swedll.h
swehouse.o: swephexp.h sweodef.h swedll.h swephlib.h swehouse.h
swejpl.o: swephexp.h sweodef.h swedll.h sweph.h swejpl.h
swemini.o: swephexp.h sweodef.h swedll.h
swemmoon.o: swephexp.h sweodef.h swedll.h sweph.h swephlib.h
swemplan.o: swephexp.h sweodef.h swedll.h sweph.h swephlib.h swemptab.h
swepcalc.o: swepcalc.h swephexp.h sweodef.h swedll.h
sweph.o: swejpl.h sweodef.h swephexp.h swedll.h sweph.h swephlib.h
swephlib.o: swephexp.h sweodef.h swedll.h sweph.h swephlib.h
swetest.o: swephexp.h sweodef.h swedll.h
感谢帮助!