OpenWrt Forum Archive

Topic: compile just one file for OpenWRT

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

Hey Guys,

I want to compile just one C-File for my OpenWRT-Router.
I followed the instructions her: http://forum.openwrt.org/viewtopic.php?id=8410

Now I have this build-environment. But what know?

What do I have to do to compile my single source File to get my small programm running on my OpenWRT-Router?

thanks for your advice.

thetruelighthouse wrote:

Am I able to use a commad like "gcc -o mybinary mysource.c" after setting the right Paths?

You need a cross-compile environment, then yes - you should be able to roughly do that.

Does not work so far...

I compiled the whole OpenWRT Package in "/home/user/whiterussian/"

Is set the paths like this:

export PATH=/home/user/whiterussian/staging_dir_mipsel/usr/bin:/home/user/whiterussian/staging_dir_mipsel/bin:/bin:/sbin:/usr/bin:/usr/sbin


PREFIX=/home/user/whiterussian/staging_dir_mipsel/bin/

export AR=$PREFIX/mipsel-linux-uclibc-ar
export AS=$PREFIX/mipsel-linux-uclibc-as
export LD=$PREFIX/mipsel-linux-uclibc-ld
export NM=$PREFIX/mipsel-linux-uclibc-nm
export CC=$PREFIX/mipsel-linux-uclibc-gcc
export CPP=$PREFIX/mipsel-linux-uclibc-cpp
export GCC=$PREFIX/mipsel-linux-uclibc-gcc
export CC=$PREFIX/mipsel-linux-uclibc-gcc
export CXX=$PREFIX/mipsel-linux-uclibc-g++
export RANLIB=$PREFIX/mipsel-linux-uclibc-ranlib

export LIBTOOL=/home/user/whiterussian/toolchain_build_mipsel/binutils-2.16.1-build/ld/libtool

export CFLAGS="-Os -s"

export LDFLAGS="-L/home/user/whiterussian/staging_dir_mipsel/usr/lib"

export CPPFLAGS="-I/home/user/whiterussian/openwrt/staging_dir_mipsel/usr/include"

now back in "/home/user/" i have a file called "test.cpp"

#include <stdio.h>
#include <stdlib.h>


int main(void) {
  printf("test\ngive it a try\n\n");
  return 0 ;
}

then tried to compile it with:
"g++ -o test test.cpp"

after that I scp'd the file "test" to my OpenWRT-Box

root@aWrt:/opt# test
root@aWrt:/opt#

... nothing happend....

(Last edited by thetruelighthouse on 16 May 2008, 16:22)

then tried to compile it with:
"g++ -o test test.cpp"

Does 'which g++' show you're using the g++ in the cross-compile environment?

If no, try '$PREFIX/mipsel-linux-uclibc-g++ -o test test.cpp'.

Hope this helps,
Charlie

thanks a lot!

I looks like it is working "a bit"...

root@aWrt:/opt# ./test
./test: can't load library 'libstdc++.so.6'
root@aWrt:/opt#

I found this Post and this Post.
How do I compile my file against the needed Library? I guess it is just a argument for the g++ compiler.

Why are you using g++ anyway?  Are you writing C or C++?

libstdc++.so.6 is provided by this package-

libstdcpp_3.4.6-10_mipsel.ipk

No need to recompile unless you're really hurting for space.

Charlie

(Last edited by ciscostu on 16 May 2008, 18:23)

thank you!
and thanks for the link!

I works again "a bit" more ;-)

root@aWrt:/opt# ./test
Aborted
root@aWrt:/opt#

I know it does not say much... Any ideas?

(Last edited by thetruelighthouse on 16 May 2008, 18:50)

aoz.syn wrote:

Why are you using g++ anyway?  Are you writing C or C++?

For my project should just C be fine.
But I got troubles using gcc:

mipsel-linux-uclibc-gcc -o test test.cpp
/tmp/ccUYdduD.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

using "mipsel-linux-uclibc-gcc -lstdc++ -o test test.cpp"
it compiles without exiting


But anyway I'm still not able to execute a self compiles binary on my OpenWRT-Box, because of the the "Aborted" message - see above...
Any ideas?

Try running your app under strace to get some debugging info.

Wow, this is cool! Thanks!
Thanks for your help so far!

root@aWrt:/opt# strace test
execve("/usr/bin/test", ["test"], [/* 10 vars */]) = 0
svr4_syscall()                          = -1 ERRNO_4090 (Unknown error 4090)
stat("/etc/ld.so.cache", 0x7fff7a90)    = -1 ENOENT (No such file or directory)
open("", O_RDONLY)                      = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=10370, ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2aaae000
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\10\0\1\0\0\0 \5\0\000"..., 4096) = 4096
old_mmap(NULL, 344064, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2aaed000
old_mmap(0x2aaed000, 10296, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, -1, 0) = 0x2aaed000
old_mmap(0x2ab2f000, 2178, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x2ab2f000
old_mmap(0x2ab30000, 68976, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x2ab30000
close(3)                                = 0
munmap(0x2aaae000, 4096)                = 0
open("/lib/libm.so.0", O_RDONLY)        = 3
fstat(3, {st_mode=0, st_size=26098, ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 715841780, 0x2aaed000) = 0x2aaae000
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\10\0\1\0\0\0000\f\0"..., 4096) = 4096
old_mmap(NULL, 290816, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2ab41000
old_mmap(0x2ab41000, 25932, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, -1, 0) = 0x2ab41000
old_mmap(0x2ab87000, 1522, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x2ab87000
close(3)                                = 0
munmap(0x2aaae000, 4096)                = 0
open("Ì®*X|gcc_s.so.1", O_RDONLY)    = 3
fstat(3, {st_mode=0, st_size=59178, ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2aaae000
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\10\0\1\0\0\0\0\30\0"..., 4096) = 4096
old_mmap(NULL, 323584, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2ab88000
old_mmap(0x2ab88000, 56980, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x2ab88000
old_mmap(0x2abd6000, 1834, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x2abd6000
close(3)                                = 0
munmap(0x2aaae000, 4096)                = 0
open("Ì®*X|¸zH«ª*/lib/libgcc_s.so.1", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=401919, ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2aaae000
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\10\0\1\0\0\0\20\272"..., 4096) = 4096
old_mmap(NULL, 684032, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2abd7000
old_mmap(0x2abd7000, 394356, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, -1, 0) = 0x2abd7000
old_mmap(0x2ac78000, 4607, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x2ac78000
old_mmap(0x2ac7a000, 15768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, 3, 0x61000) = 0x2ac7a000
close(3)                                = 0
munmap(0x2aaae000, 4096)                = 0
open("/lib/lib¨zH«ª*/lib/libc.so.0", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=401919, ...}) = 0
close(3)                                = 0
open("Ì®*X|zH«ª*/lib/libc.so.0", O_RDONLY) = 3
fstat(3, {st_mode=0, st_size=0, ...})   = 0
close(3)                                = 0
open("/lib/libc.so.0", O_RDONLY)        = 3
fstat(3, {st_mode=0, st_size=401919, ...}) = 0
close(3)                                = 0
ioctl(0, TIOCNXCL, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TIOCNXCL, {B38400 opost isig icanon echo ...}) = 0
getuid()                                = 0
getgid()                                = 0
setgid(0)                               = 0
setuid(0)                               = 0
exit(1)                                 = ?
Process 751 detached

looks like it is looking for a /etc/ld.so.cache is missing...
I guess my program needs to look somewhere else for its libraries....

Andy Ideas?

(Last edited by thetruelighthouse on 16 May 2008, 21:06)

HEY!

I just got my first test working! ;-)

I used the command "mispel-linux-uclibc-gcc -O -o test test.cpp"
the option "-O" was the key... I have no glue what this option does, but it works!

The documentation of gcc says something that this prams are automatically passed to various sub-processes invoked by gcc...

Thank you very much for your support!

The discussion might have continued from here.