首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为OpenWRT和/或OpenWRT编写Hello

如何为OpenWRT和/或OpenWRT编写Hello
EN

Stack Overflow用户
提问于 2012-09-06 18:25:35
回答 1查看 5.8K关注 0票数 4

我在LinksysWRT54G-V4上运行一个Hello程序,运行dd或OpenWRT。

现在这个路由器正在运行dd,原因我将在下面解释。我想把这个路由器切换到OpenWRT,因为我还不能构建dd或它的工具链。我“假设”OpenWRT工具链应该生成可执行的二进制文件,这些二进制文件也将在dd上运行。

OpenWRT的构建非常简单,因为它有一个很好的菜单驱动的make。使用这个方便的工具,我构建了一个工具链,它将交叉编译从我的x86 Ubuntu到一个MIPS目标。

按照指示,我能够构建OpenWRT并为brcm47xx和brcm63xx生成图像。

例如,下面是我的小Hello程序的成功编译:

代码语言:javascript
复制
jim@ubuntu:~/Desktop/tests$ cat helloC.c
#include <stdio.h>
int main (int argc, char **argv)
{
  printf("Hello World\n");
  return 0;
}
jim@ubuntu:~/Desktop/tests$
jim@ubuntu:~/Desktop/tests$ mipsel-openwrt-linux-gcc -o HelloWorld helloC.c
jim@ubuntu:~/Desktop/tests$
jim@ubuntu:~/Desktop/tests$ file HelloWorld
HelloWorld: ELF 32-bit LSB executable, MIPS, MIPS32 version 1, dynamically linked (uses shared libs), with unknown capability 0xf41 = 0x756e6700, with unknown capability 0x70100 = 0x3040000, not stripped
jim@ubuntu:~/Desktop/tests$

可悲的是,当我试图在运行dd的WRT54G-V4上运行HelloWorld时,我会遇到一个seg错误。

看看维基百科,我看到这个路由器使用的是Broadcom BCM5352。

当我通过OpenWRT/主干目录运行menuconfig时,我没有看到BCM5352的选项,这就是为什么我不愿意用我在brcm47xx或brcm63xx目录中创建的映像来刷新路由器的原因。我不想猜错了,把路由器砌成砖块。

问题1 -我应该选择使用menuconfig来针对WRT54G-V4和它的BCM5352芯片组的哪个Broadcom配置?

问题2 -我上面生成的'HelloWorld‘可执行文件是直接从54G上的命令行运行,还是必须使其成为每个coding的包?

提亚

EN

回答 1

Stack Overflow用户

发布于 2016-07-23 12:18:15

您可以按照官方的方法操作(来自:http://www.dd-wrt.com/forum/viewtopic.php?p=21499&sid=de90601a8d51747d1c8ccec29284127d)

代码语言:javascript
复制
1. The helloworld.c source
Code:   
#include <stdio.h>

int main ( void ) {
        printf( "Hello world!\n" );
}   

2. Get and unpack the toolchain in your homedir
Code:   
cd ~
wget ftp://ftp.dd-wrt.com/sourcecode/toolchains.x86.debian.sp1.tar.bz2
tar -jxf toolchains.x86.debian.sp1.tar.bz2  

3. Add the path to your cross-compiler executable to your path environment variable and compile helloworld.c
Code:   
PATH=~/toolchains/4.1.0-uclibc-0.9.28/bin:$PATH mipsel-linux-uclibc-gcc helloworld.c -o helloworld  

4. Check if its correctly compiled with the cross-compiler
Code:   
file helloworld
helloworld: ELF 32-bit LSB executable, MIPS, version 1 (SYSV), dynamically linked (uses shared libs), not stripped  

5. Finally, transfer the helloworld binary file to your router, set the executable bit and run it.

用Ubuntu6.06.1LTS测试。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12306165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档