OpenWrt Forum Archive

Topic: How to compile with gcc inside OpenWRT

The content of this topic has been archived on 16 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,

I have a "Linksys WRT1200AC" router running "CC 15.05.1" and after installing "gcc_4.8.3-1_mvebu.ipk" and all other required packages I've tried to compile a C source file (something easy, similar to "hello world") with the command:

#gcc mysource.c -o myprogram
#chmod +x myprogram

#./myprogram
myprogram: line 1: syntax error: unexpected word (expecting ")")

The compiler gives me no errors or warnings, but the program can't be started.
It's like installing a .ipk package from a different arch to your router.
So I think that gcc is compiling my source for a different CPU/Arch.
This is the cpu type: "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)

What is the correct command line to compile my sources inside openwrt with the right CPU/Arch option?
I've tried with different "-march/-mcpu" but no success.

This is with verbose on:

# gcc -v mysource.c -o mysource
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' 'mysource' '-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 mysource.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
Compiler executable checksum: 15d26b4bf239f8c7940849d852232ad6
COLLECT_GCC_OPTIONS='-v' '-o' 'mysource' '-mfloat-abi=soft' '-mtls-dialect=gnu'
 as -v -mfloat-abi=soft -meabi=5 -o /tmp/ccCYm2i5.o /tmp/ccojawQz.s
GNU assembler version 2.24 (arm-openwrt-linux-uclibcgnueabi) using BFD version (GNU Binutils) 2.24
COMPILER_PATH=/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/:/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/:/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/:/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/:/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/
LIBRARY_PATH=/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/:/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'mysource' '-mfloat-abi=soft' '-mtls-dialect=gnu'
 /usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/collect2 --eh-frame-hdr -dynamic-linker /lib/ld-uClibc.so.0 -X -m armelf_linux_eabi -o mysource /usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/crt1.o /usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/crti.o /usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/crtbegin.o -L/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3 -L/usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/../../.. /tmp/ccCYm2i5.o -lgcc_s -lc -lgcc_s /usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/crtend.o /usr/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/crtn.o

(Last edited by OpenUser on 6 May 2016, 16:39)

The topic is not relevant to OpenWrt. Start here.

But this is a OW package.
I'll probably ask the maintainer: Christian Beier

# opkg info gcc
Package: gcc
Version: 4.8.3-1
Depends: libc, binutils, libstdcpp
Status: install user installed
Section: devel
Architecture: mvebu
Maintainer: Christian Beier <cb[a_t]shoutrlabs.com>
MD5Sum: e945fe1b5a2265263ad76ad1c859282e
Size: 20123737
Filename: gcc_4.8.3-1_mvebu.ipk
Source: feeds/packages/devel/gcc
Description: build a native toolchain for compiling on target
Installed-Time: 1462466890

Kaspersky A/V runs on Windoze. For issues with the package does one contact M$?

Max Hopper wrote:

The topic is not relevant to OpenWrt. Start here.

Max I've followed your advice and post my question on  stackoverflow and after few days of "nothing" I found the answer be myself...


This is the way it was working for me.

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

The discussion might have continued from here.