狗趴(GodPub),开源硬件学习与实践

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 12603|回复: 0
打印 上一主题 下一主题

【Joytag 香蕉R1学习】OpenWrt for R1, Hello World!

[复制链接]

84

主题

143

帖子

725

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
725
QQ
跳转到指定楼层
楼主
发表于 2015-2-22 18:16:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
原文信息

标题:【Joytag 香蕉R1学习】OpenWrt for R1, Hello World!
连接:http://forum.godpub.com/thread-84-1-1.html
备注:狗趴论坛首发,转载请注明出处。



折腾缘起


在之前的一系列文章中,我们自动组装了一个OpenWrt for R1,使R1具备了有线以及无线路由器的基本功能。
但是如果仅仅是路由器功能,似乎就不值得折腾了,所以这篇文章,我们探索一下如何运行c语言程序。
关于如何组装OpenWrt for R1,请参考:
【Joytag 香蕉R1学习】自己动手组装OpenWrt for R1(全)


程序代码

首先我们用VI编辑器,编写如下代码,并保存为hello.c
  1. #include <stdio.h>
  2. int main()
  3. {
  4.         printf("Hello World!\n");
  5. }
复制代码
想必大家都不陌生,哈哈。

然后使用如下命令尝试编译:
  1. # gcc hello.c -o hello
复制代码

会出现如下错误,原因是GCC默认没有安装:
  1. /bin/ash: gcc: not found
复制代码

使用如下命令安装gcc
  1. # opkg update
  2. # opkg install gcc
复制代码

再次尝试编译,编译命令以及错误信息如下:
# gcc hello.c -o hello
/usr/bin/ld: error: hello uses VFP register arguments, /tmp/ccMMcyHs.o does not
/usr/bin/ld: failed to merge target specific data of file /tmp/ccMMcyHs.o
collect2: error: ld returned 1 exit status

搜索了一下,使用如下编译器参数即可避免:
  1. -mfloat-abi=hard
复制代码
参考连接:http://stackoverflow.com/questio ... ble-not-object-file

亦即:
  1. # gcc -mfloat-abi=hard hello.c -o hello
复制代码

执行:
  1. # ./hello
复制代码
我们就会看到熟悉的输出。



ARM Options


-mfloat-abi=name
    Specifies which floating-point ABI to use. Permissible values are: ‘soft’, ‘softfp’ and ‘hard’.

    Specifying ‘soft’ causes GCC to generate output containing library calls for floating-point operations. ‘softfp’ allows the generation of code using hardware floating-point instructions, but still uses the soft-float calling conventions. ‘hard’ allows generation of floating-point instructions and uses FPU-specific calling conventions.

    The default depends on the specific target configuration. Note that the hard-float and soft-float ABIs are not link-compatible; you must compile your entire program with the same ABI, and link with a compatible set of libraries.

https://gcc.gnu.org/onlinedocs/g ... dex-mfloat-abi-1358



总结

  • 安装gcc
  • 使用-mfloat-abi=hard 参数



参考连接

http://stackoverflow.com/questio ... ble-not-object-file
https://gcc.gnu.org/onlinedocs/g ... dex-mfloat-abi-1358
http://blog.chinaunix.net/uid-20701157-id-1891104.html
http://blog.sina.com.cn/s/blog_602f87700100r5xe.html
http://houh-1984.blog.163.com/bl ... 834201211112129167/
http://blog.csdn.net/sonach/article/details/6972303

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
天理路上甚宽,稍游心,胸中便觉广大宏朗;
人欲路上甚窄,才寄迹,眼前俱是荆棘泥涂。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|狗趴(GodPub) Arduino&Raspberry Pi开源硬件学习与实践[QQ群:20085629]  

GMT+8, 2024-4-27 00:52 , Processed in 0.032258 second(s), 31 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表