5

I bought a Chinese P2P camera and there was no MJPEG stream, so I wanted to compile mjpg-streamer for it. Here's my CPU's info:

# cat /proc/cpuinfo 
system type             : Ralink SoC
processor               : 0
cpu model               : MIPS 24K V4.12
BogoMIPS                : 239.61
wait instruction        : yes
microsecond timers      : yes
tlb_entries             : 32
extra interrupt vector  : yes
hardware watchpoint     : yes
ASEs implemented        : mips16 dsp
VCED exceptions         : not available
VCEI exceptions         : not available

# uname -a
Linux (none) 2.6.21 #878 Tue Oct 29 09:53:25 CST 2013 mips unknown

I tried to use Sourcery CodeBench for MIPS GNU/Linux (latest version) and attempted to compile a simple 'Hello world' example with this command:

$ mips-linux-gnu-gcc -Wall hello.c -o hello

After execution I received the following message:

# ./hello 
./hello: line 1: ELF@04: not found
./hello: line 2: syntax error: "(" unexpected

Next I tried to recompile with this command:

$ mips-linux-gnu-gcc -mips16 -Wall hello.c -o hello

But the result was:

# ./hello 
./hello: line 1: syntax error: "(" unexpected
  • Am I using the wrong compiler, if so which is the correct one?
  • Am I missing or using the wrong arguments?

EDIT:

$readelf -h HKIPC #Extracted file from the device
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           MIPS R3000
  Version:                           0x1
  Entry point address:               0x406420
  Start of program headers:          52 (bytes into file)
  Start of section headers:          643764 (bytes into file)
  Flags:                             0x10001007, noreorder, pic, cpic, o32, mips2
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         6
  Size of section headers:           40 (bytes)
  Number of section headers:         25
  Section header string table index: 24

$file HKIPC 
HKIPC: ELF 32-bit LSB executable, MIPS, MIPS-II version 1 (SYSV), dynamically linked (uses shared libs), stripped

-

$readelf -h hello #Compiled with mips-linux-gnu-gcc -mips2 -EL -mabi=32 hello.c  -o hello
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 01 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       1
  Type:                              EXEC (Executable file)
  Machine:                           MIPS R3000
  Version:                           0x1
  Entry point address:               0x400430
  Start of program headers:          52 (bytes into file)
  Start of section headers:          2732 (bytes into file)
  Flags:                             0x70001005, noreorder, cpic, o32, mips32r2
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         8
  Size of section headers:           40 (bytes)
  Number of section headers:         34
  Section header string table index: 31

$file hello
hello: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs), with unknown capability 0xf41 = 0x756e6700, with unknown capability 0x70100 = 0x1040000, not stripped
botzko
  • 291
  • 1
  • 3
  • 8

1 Answers1

2

Camera's libc does not match the libc used for the toolchain. In this case the program must be compiled statically adding -static switch. After this 'Hello world' is executable on the device. Another solution is to add all required shared libraries (I haven't tested this).

People from #mipslinux irc channel helped me to solve this problem - thank you.

Faheem Mitha
  • 34,649
  • 32
  • 119
  • 183
botzko
  • 291
  • 1
  • 3
  • 8
  • I seem to be trying to compile for the same device as you, I've tried your method `mips-linux-gnu-gcc -mips16 -static -Wall hello.c -o hellomips16`, also tried without `-mips16` and I keep getting the same errors `'(' unexpected`. Can you provide more details on how you accomplished this? – Juicy Feb 01 '15 at 23:48