OpenWrt Forum Archive

Topic: Compiling programs for the wrt54g

The content of this topic has been archived on 2 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

hey,

i'm kinda new to linux, but i'm getting there....

For the past few months, I've wanted to get a large RC car, put a computer on it, and drive that around. But my motherboard, a MicroATX (22x22 cm) will only fit on **LARGE** RC cars, and I'm kinda using it right now. But the router - what a great small, wireless, linux platform! And using the GPIO pins discovered by the developers of the SD card mod, that's the critical components that I needed. All I need to do is add a small driver chip like the SN754410. Its outputs would go to the motors and the inputs would be the GPIO lines. So all I need is a small script to read bytes from a socket and output to the GPIO lines.

I've got the GPIO script to control the gpio lines. I got a sample socket script from http://www.linuxgazette.com/issue74/tougher.html . It runs fine on Slackware, but it gives either "permission denied", or after I fixed that, i get unexpected "(" errors. Here's the telnet transcript:

@OpenWrt:/rccar# ./simple_server
/bin/ash: ./simple_server: Permission denied
@OpenWrt:/rccar# sh simple_server
simple_server: 1: Syntax error: "(" unexpected

It doesn't say "root@OpenWrt" because I added a password, then wanted to remove it, but it still would only run SSH; I renamed the passwd files /etc and now telnet works, but only displays "@OpenWrt" instead of root@OpenWrt.. whatever, it works.

To stay on target: The script uses some socket modules; in another post, I read that glib should have those and that's not the problem - it's just me. For compiling on Slackware I just use "make" or "gcc -c" - OpenWrt doesn't have gcc, so I have to compile on the PC and send it over (I have to get NFS working, too... right now, I put it on ftp and wget it on the router. must.. get...nfs... ). But I fear that gcc is compiling for my i686 (AMD Sempron).

Now to the real question: How can I force gcc to compile for a different platform? I just realized that I could check the "man" page - it says that "-c" removes linking. Could that be the problem? The man page for gcc is 8,778 lines long. I don't need a whole book on it; just one thing at a time - how to compile for a different platform.

Thanks for helping me out. smile

(Last edited by flyashi on 30 Jun 2005, 01:44)

flyashi wrote:

@OpenWrt:/rccar# sh simple_server
simple_server: 1: Syntax error: "(" unexpected

The shell on OpenWRT is fairly basic. If you use some bashism, it will not work.

flyashi wrote:

To stay on target: The script uses some socket modules; in another post, I read that glib should have those and that's not the problem - it's just me. For compiling on Slackware I just use "make" or "gcc -c" - OpenWrt doesn't have gcc, so I have to compile on the PC and send it over (I have to get NFS working, too... right now, I put it on ftp and wget it on the router. must.. get...nfs... ). But I fear that gcc is compiling for my i686 (AMD Sempron).

Now to the real question: How can I force gcc to compile for a different platform? I just realized that I could check the "man" page - it says that "-c" removes linking. Could that be the problem? The man page for gcc is 8,778 lines long. I don't need a whole book on it; just one thing at a time - how to compile for a different platform.

Look out the documentation about howto make a .ipkg. You will have the whole procedure. This is not a one step procedure because you need to setup a cross compiling toolchain. This is not an hard task with the tools provided by OpenWRT.

You may also look at this : http://forum.openwrt.org/viewtopic.php?pid=8899

Isn't there a way to run just one script without making an entire package? What about the gpio script used in the LED System Load Monitor mod ( http://openwrt.org/OpenWrtDocs/Customiz … 681c50cbb5 ) ? That seems to be just one source file, compiled to one script... Anyone know how I can do that?

(Last edited by flyashi on 30 Jun 2005, 15:25)

flyashi wrote:

Isn't there a way to run just one script without making an entire package? What about the gpio script used in the LED System Load Monitor mod ( http://openwrt.org/OpenWrtDocs/Customiz … 681c50cbb5 ) ? That seems to be just one source file, compiled to one script... Anyone know how I can do that?

The package you mention is already compiled. Look at the thread I mentioned before or the source of some packages of OpenWRT, this is not as hard as you may believe.

If you really want to do it by hand, you first need to setup the cross compilation tool chain. This means that you should compile OpenWRT at least once.

OK.... so if anyone is having similar problems, i got something to work

That "something" is being able to compile [mbm]'s gpio program from source, and run it on the router! Well, it's a start. I've tried about five times to compile openwrt, but it never finishes; this last time it got past the toolchain setup, so that worked. Using buildroot-documentation.html in the docs/ directory, I was able to get at least thus far.

The packaging Makefile still scares me a bit; and I don't need packaging. But compiling programs is really easy - run "mipsel-linux-gcc -o outfile infile.cpp" with /whrever/you/put/openwrt/staging_dir_mipsel/bin as part of the path variable (see the buildroot-documentation.html doc on how to do that). So that works!

I've even managed to compile my own trivial program that prints "vasya" to the screen.

Next, I need to add sockets. Oh... fun. A very good tutorial on linux socket programming is  http://www.linuxgazette.com/issue74/tougher.html but that's for c++ and I don't think that there is c++ support available for the wrt54g (i've downloaded uclibc and glibc; i stil get "can't load library 'libstdc++.so.6'" for c++ programs; c programs work fine. The linuxgazette article is for c++ - now i have to learn sockets for c!

  - flyashi [@gmail.com]

I am just getting started with compiling programs for the WRT and cannot get hello world to run.

#include <stdio.h>
int
main()
{
     (void) printf("Hello World");
     return (0);
}

When I try to run hello on the wrt54gs by typing /bin/usr/bin/hello at the root@OpenWrt: prompt...
I get:
ash: /bin/usr/bin/hello :not found

Here is my procedure:
1. mipsel-linux-gcc -Wall -o hello hello.c   //compile
(in a //hello directory) and get an output file on my red hat machine.
2.  chmod +x hello //to get permissions correct.
3.  cp hello /var/www/html  // copy the file to the root for Apache
4.  telnet 192.168.1.1    // into the router
5.  cd /bin/usr/bin
6.  wget http://192.168.1.106/hello  // which gets the file
7.  ls -la // to make sure the file is executable
8.  ./hello  // returns
    ash: ./hello: not found

The toolchain seems to be installed correctly and built with no problems from the scripts provided with it.  I keep thinking maybe I am missing some library because when, on my red hat machine, I do a file hello, I get

hello: ELF 32-bit LSB MIPS-I executable, MIPS, version 1 (SYSV), for GNU/Linux 2.2.15, dynamically linked (uses shared libs), not stripped


Any suggestions:

Not sure what -Wall does, but try using ipkg to install glibc and uclibc. That should solve most library problems. hmm

Also, you might try to run the chmod command on the router instead of the PC because I don't believe file permissions get transfered across with wget. big_smile That might actually be it. cool

It's more than that..  I had the same problem with hello.c and solved it by compiling with -static
bizcad: Use mipsel-linux-strip on the binary before transferring.  654KB is better than 2.8MB smile

/tmp # ls -l hello
-rwxr--r--    1 root     root       654380 Aug  2 23:41 hello
/tmp # ./hello
Hello World
/tmp #

-static makes the binaries ginormous

is there any other way to make something i wrote in C run? i installed glib1

thanks

0

Don't forget to strip the binary after compiling so they aren't so ginormous (that won't help make them run though).

Please use/try the new BuildingPackagesHowTo at http://wiki.openwrt.org/BuildingPackagesHowTo to port and build packages for OpenWrt.

Feedback is welcome.

(Last edited by olli_04 on 14 Sep 2005, 17:03)

Try to compile with "mipsel-linux-uclibc-gcc".
I've solve with it.

Bye

The discussion might have continued from here.