makefile与交叉编译环境

wushengjun_85 2011-08-03 08:04:27
Makefile文件
obj=main.o buf_send.o tcp_bind.o hua_cheng.o doit_pthread.o shang_chuan.o \
time_jiaodui.o changee.o\
dianchi_stop.o dianchi_suspend.o dianchi_regain.o power_down_recover_or_cl
ean.o\
changeIP.o alarmLed_control.o google.o time_test.o pthread_fun.o

target=main
#cc=gcc
cc= arm-none-linux-gnueabi-
C=-g
LP=-lpthread

$(target):$(obj)
$(cc)gcc $(C) $(LP) $^ -o $@
clean:
rm -rf *.o main
make时出错:

cc -c -o main.o main.c
cc -c -o buf_send.o buf_send.c
cc -c -o tcp_bind.o tcp_bind.c
cc -c -o hua_cheng.o hua_cheng.c
cc -c -o doit_pthread.o doit_pthread.c
doit_pthread.c: In function ‘doit_pthread’:
doit_pthread.c:100: warning: passing argument 3 of ‘pthread_create’ from incompa
tible pointer type
cc -c -o shang_chuan.o shang_chuan.c
cc -c -o time_jiaodui.o time_jiaodui.c
cc -c -o changee.o changee.c
cc -c -o dianchi_stop.o dianchi_stop.c
cc -c -o dianchi_suspend.o dianchi_suspend.c
cc -c -o dianchi_regain.o dianchi_regain.c
cc -c -o power_down_recover_or_clean.o power_down_recover_or_clean.c
cc -c -o changeIP.o changeIP.c
cc -c -o alarmLed_control.o alarmLed_control.c
cc -c -o google.o google.c
cc -c -o time_test.o time_test.c
cc -c -o pthread_fun.o pthread_fun.c
arm-none-linux-gnueabi-gcc -g -lpthread main.o buf_send.o tcp_bind.o hua_cheng.o
doit_pthread.o shang_chuan.o time_jiaodui.o changee.o dianchi_stop.o dianchi_su
spend.o dianchi_regain.o power_down_recover_or_clean.o changeIP.o alarmLed_contr
ol.o google.o time_test.o pthread_fun.o -o main
/root/softback/arm-2007q1/bin/../lib/gcc/arm-none-linux-gnueabi/4.2.0/../../../.
./arm-none-linux-gnueabi/bin/ld: main.o: Relocations in generic ELF (EM: 3)
main.o: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make: *** [main] E"

我没有用交叉编译是,make是没有错误的。
我单独用arm-none-linux-gnueabi-gcc 编译单个文件时也没有错误。
希望大家帮帮忙,给我指点一下迷津。
在此感谢大家了。
...全文
717 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
grandjack520 2014-02-19
  • 打赏
  • 举报
回复
这里用到了编译C程序的隐含规则,其推导隐晦规则的命令是 “$(CC) –c $(CPPFLAGS) $(CFLAGS)” 建议楼主在定义变量时也按照这样定义即可
wushengjun_85 2011-08-06
  • 打赏
  • 举报
回复
谢谢楼上,单个编译,没用makefile是可以的。
已经解决我的燃眉之急。
但是用makefile写还是需要的。
这个问题不知何时能解决。
不过还是要谢谢你的帮忙。
wushengjun_85 2011-08-04
  • 打赏
  • 举报
回复
还是上次的错误信息。
不知道怎么回事。
lidisha 2011-08-04
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wushengjun_85 的回复:]

首先感谢上边两位,我按照你们给的方法试了一下,
还是有问题。
希望再次指导。
[/Quote]现在还是报错?出错信息呢?
wushengjun_85 2011-08-04
  • 打赏
  • 举报
回复
首先感谢上边两位,我按照你们给的方法试了一下,
还是有问题。
希望再次指导。
yong_f 2011-08-04
  • 打赏
  • 举报
回复
Makefile文件应该改成这样
obj=main.o buf_send.o tcp_bind.o hua_cheng.o doit_pthread.o shang_chuan.o \
time_jiaodui.o changee.o\
dianchi_stop.o dianchi_suspend.o dianchi_regain.o power_down_recover_or_cl
ean.o\
changeIP.o alarmLed_control.o google.o time_test.o pthread_fun.o

target=main
#cc=gcc
cc= arm-none-linux-gnueabi-
C=-g
LP=-lpthread

$(target):$(obj)
$(cc)gcc $(C) $(LP) $^ -o $@
.c.o:
$(cc)gcc -c $< S(C)        #增加这两句就可以了
clean:
rm -rf *.o main
lidisha 2011-08-04
  • 打赏
  • 举报
回复
编译器设置错啦。前面的文件编译的时候用的是cc,也就是x86上面的编译器,而连接生存main的时候使用的是arm的编译器,所以会无法读取x86编译器编译的文件,提示格式错误。
把main的编译器也改成arm-none-linux-gnueabi-gcc应该就可以了
wushengjun_85 2011-08-04
  • 打赏
  • 举报
回复
非常感谢,
我等了很久终于有人回复了。
我先试一下!
李迟 2011-08-04
  • 打赏
  • 举报
回复
main.o: could not read symbols: File in wrong format
有理由怀疑前面所有的
cc -c -o xxxxxxxxxxxxx
都是使用主机上的编译器,后面却使用交叉编译器编译生成的.o文件,格式不正确。
楼主可以试试
%.o: %.c
$(cc)gcc -c $^ xxxxx
就是将.o也用交叉编译器编译一次。
具体命令一时记不得了,我都是用以前写的Makefile模板,不好意思。

lidisha 2011-08-04
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 wushengjun_85 的回复:]

还是上次的错误信息。
不知道怎么回事。
[/Quote]贴出了你的makefile,修改之后的,还是执行的出错信息看下。
或者你手动编译每一个模块好了,最后手动编译main文件。看下是不是还是会出错

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧