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

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz

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

2015-2-22 18:22| 发布者: 卓泰科技| 查看: 4369| 评论: 0|原作者: 卓泰科技|来自: 狗趴技术论坛

摘要: 本文探讨如何在OpenWrt for R1(Lamobo R1)系统上运行c语言程序(Hello World)。
原文信息

标题:【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/

鲜花

握手

雷人

路过

鸡蛋

相关阅读

相关分类

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

GMT+8, 2024-5-2 05:59 , Processed in 0.031424 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

返回顶部