[英]Writing and Compiling Program For OpenWrt
我有一個在 OpenWRT 下工作的帶有 MIPS arch 的嵌入式設備
系統類型:聯發科 MT7628AN ver:1 eco:2
機器:WRTnode2P 處理器:0
CPU型號:MIPS 24KEc V5.5
我想編譯通過我的電腦(ubuntu)用C編譯一個小程序
#include <stdio.h>
int main(void){
printf("HelloWorld");
return 0;
}
要編譯它,我使用 mips-linux-gnu-gcc 命令
mips-linux-gnu-gcc -march=24kec -mabi=32 hello.c -o hello
我向我的設備發送 hello 程序並制作一個 chmod 755
chmod 755 hello
當我嘗試執行它時出現錯誤
root@openWrt:/www# ./hello
./hello: line 1: syntax error: unexpected word (expecting ")")
我不明白發生了什么,我嘗試了一些其他命令來編譯它,就像帶參數一樣:-EB 或 -EL 與否,-static 與否,-mabi=32 與否,但我有同樣的問題。
有誰能幫幫我嗎?
謝謝
[更新]
我向現有文件發送文件命令,這是結果
fw3: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked, interpreter /lib/ld., for GNU/Linux 3.2.0, stripped
所以我用這個命令編譯我的程序
mipsel-linux-gnu-gcc -march=24kec -mips32r2 -mips16 hello.c -o hello
現在我有了這個文件命令結果
hello: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld., for GNU/Linux 3.2.0, BuildID[sha1]=cd12319441c530606d52d96478719b06a7b215a7, not stripped
現在我讀了我的遠程程序的 ELF
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: 0x402c40
Start of program headers: 52 (bytes into file)
Start of section headers: 78592 (bytes into file)
Flags: 0x74001005, noreorder, cpic, o32, mips16, mips32r2
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 10
Size of section headers: 40 (bytes)
Number of section headers: 31
Section header string table index: 30
這是我的 hello 程序 readelf 命令
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: 0x4005c0
Start of program headers: 52 (bytes into file)
Start of section headers: 6700 (bytes into file)
Flags: 0x74001007, noreorder, pic, cpic, o32, mips16, mips32r2
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 11
Size of section headers: 40 (bytes)
Number of section headers: 33
Section header string table index: 30
有兩個不同的 ABI 版本,在標志中有圖片
如果我嘗試啟動我的 hello 程序,則會出現此錯誤
hello: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
我嘗試添加 -static 參數,但在啟動 hello 程序時出現此錯誤
Illegal instruction
我總是被這個問題困住。
我有一個類似的問題,並通過將 Architect 設置為mipsle來修復它。 我正在使用 Go 在此設備上為 linux/mips 構建二進制文件,
system type : MediaTek MT7620A ver:2 eco:6
cpu model : MIPS 24KEc V5.0
isa : mips1 mips2 mips32r1 mips32r2
ASEs implemented : mips16 dsp
第一次失敗,
macbook:# cat main.go
package main
import (
"fmt"
)
func main() {
fmt.Println("hello, mips")
}
############# Setting GOARCH=mips ============
macbook:# GOOS=linux GOARCH=mips GOMIPS=softfloat go build -o hello-mips
openwrt:# ./hello-mips
./hello-mips: line 1: syntax error: unexpected "("
然后我意識到 CPU 架構是Little-Endian ,而不是默認的 Big-Endian。 所以我更改了構建參數,現在它成功了。
############# Setting GOARCH=mipsle ============
macbook:# GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -o hello
openwrt:# ./hello
hello, mips
你的CPU型號和我的一樣,只是版本MIPS 24KEc V5.5
,它也必須是mipsle(mipsel)。 希望能幫助到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.