Problem with execution of an own c++ application

9 posts / 0 new
Last post
ande
ande's picture
Problem with execution of an own c++ application

Hi all!

I have a problem, no idea what could be wrong and wonder if anybody can help.

I'm sitting in front of a Netgear-WNR3500L with DD-WRT v24-sp2 std, Linux Kernel 2.6.26.111 and BusyBox v1.13.4.

I wrote and compiled a simple c++ program with a mips-compiler, that was build with crosstool. crosstool used gcc-3.4.5, glibc-2.3.6 and kernel sources 2.6.9.

So far everything was ok and I transmitted the application to the /jffs/usr/sbin folder of the router.

Now, when I want to execute the small application I get the error-message:

  ./hello: line 1: syntax error: "(" unexpected

 

Well, first of all: Is it possible to execute a program compiled with "kernel-sources 2.6.9" on a 2.6.26 platform?

Is it possible to "cross-compile", transmit and execute a program, or (according to a guide i found on this website) do i have to re-build the whole dd-wrt together with my program?

Any idea what i am doing wrong?

Any suggestions are very welcome!

 

Thanks!

ande
ande's picture
In addition:

In addition:

 

Execution of the command "file hello" returns:

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

 

I'm afraid, I used a wrong compiler (for Linux 2.4.18), although the kernel source was 2.6.9.

 

But i thought, wrong kernel version returns a kernel-oops.

 

So, any suggestions are very welcome! :)

 

Thanks!

Kong
Kong's picture
You should compile your

You should compile your programm with dd-wrts toolchain, this way you avoid problems with incompatible libs. You'll find a link to the dd-wrt toolchain on the dd-wrt wiki. dd-wrt currently uses gcc_4.1.2

If you compile with a different toolchain you may have to copy the depending libs and preload them by using LD_PRELOAD.

ande
ande's picture
Thanks Kong for quick reply!

Thanks Kong for quick reply!

 

I downloaded the file http://www.dd-wrt.com/dd-wrtv2/downloads/others/sourcecode/toolchains/cu...

The problem is, that you can only use it on a 64-bit system. I'm using Ubuntu 8.04 x86 and can't find the right toolchain. Every howto i found is written for the toolchain for 64bit-systems.

 

Do you know the file or web-address of the toolchain for a 32-bit system?

 

Thanks in advance!

 

P.S.: I think need the Little Endian version (mipsel)

Kong
Kong's picture
The current toolchain is only

The current toolchain is only available in 64Bit. Unfortunately the openwrt buildchain does not allow to build the exact same gcc + uclibc anymore, so you cannot easily create it as 32Bit.

For my optware packages I'm using openwrt build environment with a more recent uclibc. This way you automatically have dependent packages like uclibc, libpthread etc. as package ready to install with ipkg

ande
ande's picture
Well, I downloaded package

Well, I downloaded package http://downloads.openwrt.org/kamikaze/7.09/atheros-2.6/OpenWrt-SDK-ather..., unpacked it, edited the Makefile and called "make".

Compiling works fine, but the linker gives the following error:

/opt/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/../lib/gcc/mipsel-linux-uclibc/3.4.4/../../../../mipsel-linux-uclibc/bin/ld: crt1.o: No such file: No such file or directory

 

I'm sure, the file crt1.o is in the lib-directory of the unpacked archive (/opt/OpenWrt.../...). It's also in the /usr/lib folder.

 

Here's a part of my Makefile:

TOOLCHAIN_PATH = /opt/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/
TOOLCHAIN_BIN_PATH = $(TOOLCHAIN_PATH)bin/mipsel-linux-uclibc-
TOOLCHAIN_LIB_PATH = $(TOOLCHAIN_PATH)lib/

#binutils:
AR = $(TOOLCHAIN_BIN_PATH)ar
AS = $(TOOLCHAIN_BIN_PATH)as
LD = $(TOOLCHAIN_BIN_PATH)ld
NM = $(TOOLCHAIN_BIN_PATH)nm
CC = $(TOOLCHAIN_BIN_PATH)gcc
CPP = $(TOOLCHAIN_BIN_PATH)cpp
GCC = $(TOOLCHAIN_BIN_PATH)gcc
CXX = $(TOOLCHAIN_BIN_PATH)g++

#Linker-Flags:
LDFLAGS= -L$(TOOLCHAIN_LIB_PATH) -l$(TOOLCHAIN_LIB_PATH)crt1.o -o

CFLAGS= -Wall -O2 \
        -I$(TOOLCHAIN_PATH)include/c++/3.4.4/ \
        -I$(TOOLCHAIN_PATH)include/ \
        -c

 

So, I don't understand, why the linker can't find crt1.o.

Do I have to define more special parameters in the Linker-Flags?

ande
ande's picture
After three days I'll give it

After three days I'll give it up.

I don't think, it's impossible, but in my opinion too much to configure, too much trying and all without a positive result.

I switched to a 64bit-processor workstation so I can use the current-toolchain-package.

 

Anyway, thanks to Kong!

 

@Developers of DD-WRT:

Please offer a precompiled toolchain, that can be used on 32bit machines! This would be very helpful and I think many people would be thankful! :)

Kong
Kong's picture
So, I don't understand, why

So, I don't understand, why the linker can't find crt1.o.

This is because it is not looking for crt1.o but crt1.o.so or crt1.o.a :-)
crt1.o is an object file not a library .a or shared library .so.

Qouting from the linker manual.

larchive
--library=archive
Add archive file archive to the list of files to link. This option
may be used any number of times. ld will search its path-list for
occurrences of "libarchive.a" for every archive specified.

On systems which support shared libraries, ld may also search for
libraries with extensions other than ".a". Specifically, on ELF
and SunOS systems, ld will search a directory for a library with an
extension of ".so" before searching for one with an extension of
".a". By convention, a ".so" extension indicates a shared library.

Another example you tell the linker to link against pthread:

-lpthread

then the linker is going to search for libpthread.so in your library path.

If you want to avoid trying read the manual.

ande
ande's picture
Hi Kong!

Hi Kong!

Thanks for this explanation! Although I haven't tried it yet, your answer will be very helpful for future projects!

And of course thanks for your patience! :)