如何在OpenWRT中使用gcc进行编译

时间:2016-05-15 14:38:11

标签: gcc openwrt

我有一台运行“OpenWrt Chaos Calmer 15.05.1”(mvebu架构)的“Linksys WRT1200AC”路由器,带有“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 ")")

编译器没有给我任何错误或警告,但程序无法启动。 这就像从不同的拱门到路由器安装.ipk软件包。 所以我认为gcc正在为不同的CPU / Arch编译我的源代码。 路由器CPU是:“Marvell Armada 38X双核@ 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

1 个答案:

答案 0 :(得分:0)

好吧,似乎这样做了;)

gcc -mabi=aapcs-linux mysource.c -o myprogram