如何在 OpenWRT 中使用 gcc 进行编译
How to compile with gcc inside OpenWRT
我有一个 "Linksys WRT1200AC" 路由器 运行 "OpenWrt Chaos Calmer 15.05.1"(mvebu 架构),安装了 "gcc_4.8.3-1_mvebu.ipk" 和所有其他必需的软件包。
我尝试使用以下命令编译 C 源文件(很简单,类似于 "hello world"):
#gcc mysource.c -o myprogram
#chmod +x myprogram
#./myprogram
myprogram: line 1: syntax error: unexpected word (expecting ")")
编译器没有给我任何错误或警告,但程序无法启动。
这就像从不同的 arch 安装 .ipk 包到路由器。
所以我认为 gcc 正在为不同的 CPU/Arch 编译我的源代码。
路由器 cpu 是:"Marvell Armada 38X dual-core @ 1.33 GHz (88F6820-A0 C133)"
# uname -a
Linux OW 3.18.23 #1 SMP Sun Jan 31 12:53:24 CET 2016 armv7l GNU/Linux
# grep 'model name' /proc/cpuinfo
model name : ARMv7 Processor rev 1 (v7l)
model name : ARMv7 Processor rev 1 (v7l)
使用正确的 CPU/Arch 选项在 openwrt 中编译我的源代码的正确命令行是什么?
我试过不同的“-march/-mcpu”但没有成功。
这是冗长的:
# gcc -v mysource.c -o myprogram
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/lto-wrapper
Target: arm-openwrt-linux-uclibcgnueabi
Configured with: /home/buildbot/slave-local/mvebu_generic/build/build_dir/target-arm_cortex-a9+vfpv3_uClibc-0.9.33.2_eabi/gcc-4.8.3/configure --target=arm-openwrt-linux --host=arm-openwrt-linux --build=x86_64-linux-gnu --program-prefix= --program-suffix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls --build=x86_64-linux-gnu --host=arm-openwrt-linux-uclibcgnueabi --target=arm-openwrt-linux-uclibcgnueabi --enable-languages=c,c++ --with-bugurl=https://dev.openwrt.org/ --with-pkgversion='OpenWrt GCC 4.8.3' --enable-shared --disable-__cxa_atexit --enable-target-optspace --with-gnu-ld --disable-nls --disable-libmudflap --disable-multilib --disable-libgomp --disable-libquadmath --disable-libssp --disable-decimal-float --disable-libstdcxx-pch --with-host-libstdcxx=-lstdc++ --prefix=/usr --libexecdir=/usr/lib --with-float=soft
Thread model: posix
gcc version 4.8.3 (OpenWrt GCC 4.8.3)
COLLECT_GCC_OPTIONS='-v' '-o' 'myprogram' '-mfloat-abi=soft' '-mtls-dialect=gnu'
/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/cc1 -quiet -v -imultilib . -imultiarch arm-linux-gnueabi mysource.c -quiet -dumpbase myprogram.c -mfloat-abi=soft -mtls-dialect=gnu -auxbase mysource -version -o /tmp/ccojawQz.s
GNU C (OpenWrt GCC 4.8.3) version 4.8.3 (arm-openwrt-linux-uclibcgnueabi)
compiled by GNU C version 4.8.3, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
ignoring nonexistent directory "/usr/local/include/arm-linux-gnueabi"
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/../../../../arm-openwrt-linux-uclibcgnueabi/include"
ignoring nonexistent directory "/usr/include/arm-linux-gnueabi"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/include
/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/include-fixed
/usr/include
End of search list.
GNU C (OpenWrt GCC 4.8.3) version 4.8.3 (arm-openwrt-linux-uclibcgnueabi)
compiled by GNU C version 4.8.3, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
嗯,好像是这样的 ;)
gcc -mabi=aapcs-linux mysource.c -o myprogram
我有一个 "Linksys WRT1200AC" 路由器 运行 "OpenWrt Chaos Calmer 15.05.1"(mvebu 架构),安装了 "gcc_4.8.3-1_mvebu.ipk" 和所有其他必需的软件包。
我尝试使用以下命令编译 C 源文件(很简单,类似于 "hello world"):
#gcc mysource.c -o myprogram
#chmod +x myprogram
#./myprogram
myprogram: line 1: syntax error: unexpected word (expecting ")")
编译器没有给我任何错误或警告,但程序无法启动。 这就像从不同的 arch 安装 .ipk 包到路由器。 所以我认为 gcc 正在为不同的 CPU/Arch 编译我的源代码。 路由器 cpu 是:"Marvell Armada 38X dual-core @ 1.33 GHz (88F6820-A0 C133)"
# uname -a
Linux OW 3.18.23 #1 SMP Sun Jan 31 12:53:24 CET 2016 armv7l GNU/Linux
# grep 'model name' /proc/cpuinfo
model name : ARMv7 Processor rev 1 (v7l)
model name : ARMv7 Processor rev 1 (v7l)
使用正确的 CPU/Arch 选项在 openwrt 中编译我的源代码的正确命令行是什么? 我试过不同的“-march/-mcpu”但没有成功。
这是冗长的:
# gcc -v mysource.c -o myprogram
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/lto-wrapper
Target: arm-openwrt-linux-uclibcgnueabi
Configured with: /home/buildbot/slave-local/mvebu_generic/build/build_dir/target-arm_cortex-a9+vfpv3_uClibc-0.9.33.2_eabi/gcc-4.8.3/configure --target=arm-openwrt-linux --host=arm-openwrt-linux --build=x86_64-linux-gnu --program-prefix= --program-suffix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls --build=x86_64-linux-gnu --host=arm-openwrt-linux-uclibcgnueabi --target=arm-openwrt-linux-uclibcgnueabi --enable-languages=c,c++ --with-bugurl=https://dev.openwrt.org/ --with-pkgversion='OpenWrt GCC 4.8.3' --enable-shared --disable-__cxa_atexit --enable-target-optspace --with-gnu-ld --disable-nls --disable-libmudflap --disable-multilib --disable-libgomp --disable-libquadmath --disable-libssp --disable-decimal-float --disable-libstdcxx-pch --with-host-libstdcxx=-lstdc++ --prefix=/usr --libexecdir=/usr/lib --with-float=soft
Thread model: posix
gcc version 4.8.3 (OpenWrt GCC 4.8.3)
COLLECT_GCC_OPTIONS='-v' '-o' 'myprogram' '-mfloat-abi=soft' '-mtls-dialect=gnu'
/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/cc1 -quiet -v -imultilib . -imultiarch arm-linux-gnueabi mysource.c -quiet -dumpbase myprogram.c -mfloat-abi=soft -mtls-dialect=gnu -auxbase mysource -version -o /tmp/ccojawQz.s
GNU C (OpenWrt GCC 4.8.3) version 4.8.3 (arm-openwrt-linux-uclibcgnueabi)
compiled by GNU C version 4.8.3, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
ignoring nonexistent directory "/usr/local/include/arm-linux-gnueabi"
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/../../../../arm-openwrt-linux-uclibcgnueabi/include"
ignoring nonexistent directory "/usr/include/arm-linux-gnueabi"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/include
/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/include-fixed
/usr/include
End of search list.
GNU C (OpenWrt GCC 4.8.3) version 4.8.3 (arm-openwrt-linux-uclibcgnueabi)
compiled by GNU C version 4.8.3, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
嗯,好像是这样的 ;)
gcc -mabi=aapcs-linux mysource.c -o myprogram