标题:【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
-
#include <stdio.h>
-
int main()
-
{
-
printf("Hello World!\n");
-
}
-
然后使用如下命令尝试编译:
- # gcc hello.c -o hello
会出现如下错误,原因是GCC默认没有安装:
- /bin/ash: gcc: not found
使用如下命令安装gcc
-
# opkg update
- # 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
搜索了一下,使用如下编译器参数即可避免:
- -mfloat-abi=hard
亦即:
-
# gcc -mfloat-abi=hard hello.c -o hello
-
执行:
- # ./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/