Jump to content
Hak5 Forums
kerravon

Compiling C code in openwrt

Recommended Posts

5 hours ago, kerravon said:

still getting command not found

[email protected]:~ OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin$ mips-openwrt-linux-uclibc-gcc –o test test.c

 

mips-openwrt-linux-uclibc-gcc: command not found

 

  path variables

export PATH=$PATH:/home/user/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/

 

 

 

export STAGING_DIR=/home/user/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2

 

Might be dumb question, but are you root? If not, try "sudo mips-openwrt-linux-uclibc-gcc"?

Share this post


Link to post
Share on other sites
Posted (edited)

You don't need high privileges to use gcc, or any part of the SDK. (You can run it as root, but it's not adviced.)
IF the PATH variable is setup correctly, you should be able to find "mips-openwrt-linux-uclibc-gcc"

When you issue a command in the terminal it looks through all the folders in the PATH variable to find the file you are trying to execute.
The reason we're adding the toolchain/bin directory to PATH is so that you can launch the "mips-openwrt-linux-uclibc-gcc" command in that terminal session.
(That file is located within the toolchain/bin directory)

If you add the "export PATH" and "export STAGING_DIR" command to ~/.bashrc you will get persistence for you user, and won't need to execute them every time you start a new terminal session.

Edited by Zylla

Share this post


Link to post
Share on other sites

usin sudo didnt make a difference

Share this post


Link to post
Share on other sites
1 hour ago, kerravon said:

usin sudo didnt make a difference

I was just curious if it was a perms issue and command only available to root, but seems not the case. This is why I said to use the whole path the the program you are starting before adding the rest of the switches and paths. You should be able to change directory to the executable and start it with ./somecommand -some blag blah blah. Make sure the file is executable and not read only as well.

Share this post


Link to post
Share on other sites

still getting command not found

[email protected]:~ OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin$ mips-openwrt-linux-uclibc-gcc –o test test.c

mips-openwrt-linux-uclibc-gcc: command not found

  path variables

export PATH=$PATH:/home/user/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/

export STAGING_DIR=/home/user/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2

So where do we go from here? dont suppose there's a disto with them already configiured and ready to go

Share this post


Link to post
Share on other sites

type:

updatedb
locate mips-openwrt-linux-uclibc-gcc

Then cd to that path. Then

./mips-openwrt-linux-uclibc-gcc test.c -o test

If still not found, I don't know other than it needs to be set to executable(chmod +x), or its not installed properly. Make sure mips-openwrt-linux-uclibc-gcc is an executable file, and not a directory.

If there are specific switches needed(I recall Zylla may have mentioned this, if not then ok) make sure to add them to compile for the device, ie: m32 when compileing for 32bit systems on a 64bit system(does not necessarily apply here, just giving as example)

Share this post


Link to post
Share on other sites

Try doing exactly this below, and report back the output you're getting.

cd /home/user/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/
./mips-openwrt-linux-uclibc-gcc test.c -o test

If it manages to find the command "mips-openwrt-linux-uclibc-gcc" after doing this, you are having issues with your environment variables somehow not working.

Share this post


Link to post
Share on other sites
Posted (edited)

hi couldn't upload screenshot so you can download it here https://www.dropbox.com/s/c5ir2ytvcy29r8p/mips_gcc.png?dl=0

Here is output from printenv

XDG_VTNR=7
SSH_AGENT_PID=2036
XDG_SESSION_ID=c1
CLUTTER_IM_MODULE=xim
SELINUX_INIT=YES
XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/user
SESSION=ubuntu
GPG_AGENT_INFO=/run/user/1000/keyring-Slx10Q/gpg:0:1
XDG_MENU_PREFIX=gnome-
SHELL=/bin/bash
VTE_VERSION=3409
TERM=xterm
SSH_AGENT_LAUNCHER=upstart
WINDOWID=25165835
UPSTART_SESSION=unix:abstract=/com/ubuntu/upstart-session/1000/1881
GNOME_KEYRING_CONTROL=/run/user/1000/keyring-Slx10Q
GTK_MODULES=overlay-scrollbar:unity-gtk-module
USER=user
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
SSH_AUTH_SOCK=/run/user/1000/keyring-Slx10Q/ssh
DEFAULTS_PATH=/usr/share/gconf/ubuntu.default.path
SESSION_MANAGER=local/ubuntuvm:@/tmp/.ICE-unix/2105,unix/ubuntuvm:/tmp/.ICE-unix/2105
XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
DESKTOP_SESSION=ubuntu
QT_QPA_PLATFORMTHEME=appmenu-qt5
JOB=dbus
PWD=/home/user/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin
[email protected]=ibus
LANG=en_US.UTF-8
GDM_LANG=en_US
MANDATORY_PATH=/usr/share/gconf/ubuntu.mandatory.path
UBUNTU_MENUPROXY=1
IM_CONFIG_PHASE=1
COMPIZ_CONFIG_PROFILE=ubuntu
GDMSESSION=ubuntu
SESSIONTYPE=gnome-session
SHLVL=1
XDG_SEAT=seat0
HOME=/home/user
LANGUAGE=en_US
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
LOGNAME=user
COMPIZ_BIN_PATH=/usr/bin/
QT4_IM_MODULE=xim
XDG_DATA_DIRS=/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-clk0qAIj2g
LESSOPEN=| /usr/bin/lesspipe %s
INSTANCE=
TEXTDOMAIN=im-config
XDG_RUNTIME_DIR=/run/user/1000
DISPLAY=:0
XDG_CURRENT_DESKTOP=Unity
GTK_IM_MODULE=ibus
LESSCLOSE=/usr/bin/lesspipe %s %s
TEXTDOMAINDIR=/usr/share/locale/
COLORTERM=gnome-terminal
XAUTHORITY=/home/user/.Xauthority
_=/usr/bin/printenv
OLDPWD=/home/user/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2
 

Edited by kerravon

Share this post


Link to post
Share on other sites

"Cannot execute binary file: exec format error"

That error message is typical if you are trying to execute a binary file compiled for another cpu-architecture.
For example when trying to run 64-bit binaries on a x86 operating-system.
What architecture-type are your Ubuntu installation? That SDK is for 64-bit.

Share this post


Link to post
Share on other sites

Sh*t its 686 so 32bit

 

  • Upvote 1

Share this post


Link to post
Share on other sites

How about reset everything, and follow a step-by-step setup procedure for everything required for the OpenWrt SDK. 

We'll just follow through after that.

Share this post


Link to post
Share on other sites

OK, will build new VM tonight, then go through the installation steps above by zylla
see where we get from there and I report progress here.

cheers

Share this post


Link to post
Share on other sites

interesting problem now, I have install a 64 bit debian vm, downloaded the chaos_calmer
toolchain as per zylla's instructions.

Copied the export paths only changing user name to mine, , it wont try to compile unless I
use the sudo command i.e

sudo ./mips-openwrt-linux-uclibc-gcc test.c -o test

it then comes up with 3 messages all saying

mips-openwrt-linux-uclibc-gcc: warning: enviroment variable 'STAGING_DIR' not defined

re applying the staging_dir export command an opening a fresh terminal makes no difference.
Can upload the VM to my dropbox if you want to look at it.

Share this post


Link to post
Share on other sites

Can you export your $PATH with the addition of the required path for the staging_dir to it? That might help.

Share this post


Link to post
Share on other sites

dumb question but how would I go about doing that

 

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

×