C语言 文件无法识别:文件格式无法识别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18438396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 07:15:58  来源:igfitidea点击:

file not recognized: File format not recognized

cmakefile

提问by harish013

when i run a make file i get this error

当我运行 make 文件时,我收到此错误

"obj/viojournal.o: file not recognized: File format not recognized collect2: ld returned 1 exit status"

“obj/viojournal.o:无法识别文件:无法识别文件格式 collect2:ld 返回 1 个退出状态”

and the make file is as follows

和make文件如下

how to fix this problem. i am using gcc compiler on centos 5.4 linx 64bit machine.

如何解决这个问题。我在 centos 5.4 linx 64 位机器上使用 gcc 编译器。

all: libvioft.so fdump syncer

CPPFLAGS = -I/usr/include/libxml2 -I../clogger -I../marshall -I../ddp  \
     -I../http -I../xml -I../nfsop  -I../include/common -I../restful \
     -I../include/oneGrid

CFLAGS = -g3 -Wall -Wextra -fPIC -DREPLICATION_ENABLED -DJOURNALING_ENABLED

#CFLAGS = -g3 -Wall -Wextra -fPIC

LDFLAGS = -Wl,-rpath=$$ORIGIN -Wl,-rpath=$$ORIGIN/../clogger \
    -Wl,-rpath=$$ORIGIN/../marshall -Wl,-rpath=$$ORIGIN/../ddp \
    -Wl,-rpath=$$ORIGIN/../http  -Wl,-rpath=$$ORIGIN/../xml \
    -Wl,-rpath=$$ORIGIN/../restful

LIBS = -lpthread -lssl -lxml2 -lbz2 -L../clogger -lclogger \
    -L../marshall -lmarshall -L../ddp -lddp -L../nfsop -lnfsop

libsources = filefs.c viojournal.c recvReplicaUpdate.c syncer.c hostops.c filetable.c updateRemoteFT.c checkpoint.c 
#libsources = filefs.c viojournal.c hostops.c filetable.c checkpoint.c container.c locks.c

libobjects = $(libsources:%.c=obj/%.o)

fttestsources = fttest2.c
fttestobjects = $(fttestsources:%.c=obj/%.o)

syncersources = syncer.c
syncerobjects = $(syncersources:%.c=obj/%.o)

#dmpsources = viodump.c hostops.c
#dmpobjects = $(dmpsources:%.c=obj/%.o)

libvioft.so: $(libobjects)
    $(CC) $(CFLAGS) -shared -o libvioft.so $(libobjects)

fdump: $(fttestobjects) libvioft.so
    $(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) -o fdump $(fttestobjects)

syncer: $(syncerobjects) libvioft.so
    $(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) -o syncer $(syncerobjects)

viodump: $(dmpobjects)
    $(CC) $(CFLAGS) $(LDFLAGS) -lpthread -o viodump $(dmpobjects)

clean: 
    rm -rf fttest viodump atar syncer libvioft.so obj

install: 
    cp -f libvioft.so ../package/lib    
#   cp -f syncer ../package/bin

obj/%.d: %.c
    $(SHELL) -ec 'mkdir -p obj && $(CC) -MM $(CPPFLAGS) $(CFLAGS) -MT $(@:.d=.o) -MT $@ $< > $@'

obj/%.o: %.c
    $(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<

include $(libsources:%.c=obj/%.d)
include $(tstsources:%.c=obj/%.d)
include $(atrsources:%.c=obj/%.d)
#include $(dmpsources:%.c=obj/%.d)

回答by rubenvb

It seems like the object file is corrupted somehow. Try deleting it to force it to be rebuilt or as @devnull suggests, do a make clean.

似乎目标文件以某种方式损坏了。尝试删除它以强制重建它,或者按照@devnull 的建议,执行make clean.

回答by bballdave025

(I would put this suggestion as a comment, but I don't have enough, Reputation yet)

(我会把这个建议作为评论,但我还不够,声誉还没有)

I ran into this error recently, and I have a couple of suggestions that might help.

我最近遇到了这个错误,我有一些可能会有所帮助的建议。

In my case, the makefile(s) in question needed different CFLAGSdepending on whether the installation was 64-bit or 32-bit. Here are some lines from the README

在我的情况下,有makefile问题的(s) 需要CFLAGS根据安装是 64 位还是 32 位而有所不同。以下是来自README

By default, the C/C++ software are compiled in 32 bits with the options (-Os) but can be compiled in 64 bits, -m64 is added to the CFLAGS variable in <certain makefiles in the project are listed>

By default, the C/C++ software are compiled in 32 bits with the options (-Os) but can be compiled in 64 bits, -m64 is added to the CFLAGS variable in <certain makefiles in the project are listed>

My suggestion is to first try adding -m64to your CFLAGS. If that doesn't work, delete the -m64and replace it with -Os.

我的建议是首先尝试添加-m64到您的CFLAGS. 如果这不起作用,请删除-m64并将其替换为-Os

That is, first try having the following line:

也就是说,首先尝试使用以下行:

CFLAGS = -g3 -Wall -Wextra -fPIC -DREPLICATION_ENABLED -DJOURNALING_ENABLED -m64

Then, from the command line, run

然后,从命令行,运行

make clean

Followed by whatever makecommands you use for your install.

其次是make您用于安装的任何命令。

If that doesn't work, change the line in question to

如果这不起作用,请将有问题的行更改为

CFLAGS = -g3 -Wall -Wextra -fPIC -DREPLICATION_ENABLED -DJOURNALING_ENABLED -Os

Then make cleanand the other makestuff.

然后make clean和其他make东西。

If some of the C objects are 64-bit and some are 32-bit (I don't know if such a situation actually exists), you might have to do something different.

如果有些 C 对象是 64 位的,有些是 32 位的(我不知道这种情况是否真的存在),您可能需要做一些不同的事情。

This worked in my case, details of which you can see here.

这在我的情况下有效,您可以在此处查看详细信息。

Please comment to let me know if it works for you.

请发表评论让我知道它是否适合你。