In place compilation: issues with configure

Hello to everyone! :slight_smile: I know it isn't the best practice and the advice is setting up a toolchain elsewhere but I need to compile just one small program to use it on my router running on OpenWrt 18.06.4 and given that compilation wouldn't be that heavy and I have extroot up and running, I've chosen for an in place compilation. I've installed gcc 5.4.0 (the latest one available in the repositories for my setup), make and all the rest I'm supposed to need (or at least I hope so!). As soon as I execute the configure script, just issuing:

./configure --prefix=/usr/

I get this error:

configure: error: C compiler cannot create executables

and if I check config.log the detailed error is this one:

configure:2872: checking whether the C compiler works
configure:2894: gcc   -L/usr/lib/ -L/lib/ conftest.c  >&5
gcc: fatal error: -fuse-linker-plugin, but liblto_plugin.so not found
compilation terminated.

Indeed, at the beginning liblto_plugin.so was actually missing but I've downloaded it and put it inside /usr/lib and declared the LDFLAGS environment variable as -L/usr/lib\ -L/lib/ which is actually being used according to the log above.
Knowing that sometimes it helps with solving similar issues (root user should be used only for the final make install), I've also tried to create a non privileged user and launch the configure script by it to no avail. I've tried to download the tar sources too (to exclude something wrong with what I needed to compile) but the outcome is EXACTLY the same. What's wrong here then? I'm rather certain I'm missing something, something stupid.
Thanks in advance to everyone for your replies! :slight_smile:

OpenWrt is not self-hosting, you need to cross-compile externally. Yes, gcc itself is packaged, but that's about it - and anything using a configure step is by definition no longer a small and simple program.

2 Likes

First of all, thanks for your reply. Much time has passed and there is the possibility I'm wrong but once ago I had a Huawei HG553 still on OpenWrt and I remember clearly I did compile directly on it. Also, what's the purpose of having a GCC package just to compile helloworld.c? I'm confident the problem, at least for this first matter, should be another. I know OpenWrt does static linking and it is quite clear it doesn't find a library which is present instead: it could be the one I've downloaded isn't suitable for static linking or something similar... Maybe it will fail anyway because of what you are saying but here the problem seems another. I would be glad to succeed with setting a toolchain up but it seems to involve downloading Gbs of packages and spending a lot of time to set it up: is it worth the effort for just using it once to compile a single program when the router resources are just enough? I don't think so. Have a nice day! :slight_smile:

Though I still believe it is at least a pity not to be able to make some light in place compilation after setting the needed environment up directly on the router, I've understood that my topic has attracted very low interest and I've been forced to set a toolchain up and cross compile what I needed.
The documentation on OpenWrt site is very well laid down as always so everything has been more or less straightforward. I've done everything on Lubuntu 19.10 Eoan Ermine 64bit (please be adviced it is a requisite because 32bit kernels aren't supported: not an issue these days). It was just enough to install all the dependencies:

sudo apt-get install subversion g++ zlib1g-dev build-essential git python python3 python3-distutils libncurses5-dev gawk gettext unzip file libssl-dev wget libelf-dev ecj fastjar java-propose-classpath

then clone OpenWrt sources:

git clone https://github.com/openwrt/openwrt.git

(everything would be downloaded into an 'openwrt' folder)
then enter inside that folder and run:

make menuconfig

select the proper target and subtarget, select the option to build a toolchain then exit (saving changes, that's clear) and run:

make

After this, it was necessary to add some tweaking by myself due to some repeated errors with make linked to json.h. I needed to install another dependency:

sudo apt-get install libjson-c-dev

which would install json.h under /usr/include/json-c/ so I needed to edit the source files arising the 'problem' each time it occurred (five times during all the build stage if I remember well) defining the right location accordingly.
Each time an error arose, I've been helped by the command:

make -j1 V=s

which clearly led me in the right direction with the needed modifications to the sources.
In the end, the toolchain was in openwrt/toolchain (being 'openwrt' the aforementioned folder where the sources are cloned by git).
It has just taken a lot of time, exactly what I expected since the beginning and what I wanted to avoid just setting the build environment up directly on the router, a real pity! I hope my experience would at least be of help to someone else. Have a nice day! :slight_smile:

Plain gcc is not enough. There needs to be the whole toolchain (plus the tweaked host tools), so that the compiled packages get compiled properly with the non standard libc (musl) etc.

1 Like

I also realized @slh had answered him and I hadn't seen it :slight_smile: So I removed it.. I appreciate the followthru though @hnyman!

Up far to late..

Hello again to everyone! :slight_smile: First of all, I care to underline that I wasn't arguing about anything, just sharing my point of view. I'm sure that if some choices have been done, there are valid reasons for them. I had to download the Lubuntu iso, all the needed dependencies and the OpenWrt sources and this lead to quite a large download while building the toolchain demanded quite a lot of time. All of this had been avoided if I had been able to do the compilation directly on the router itself but, again, I'm sure there are valid reasons to make it impossible so no arguing at all. Available space is an easy to solve issue thanks to extroot but there are others I can't even think of for sure.
At least, a toolchain needs to be set up only once and I hope I would need it again and, apart from this, I've learnt something new. I take the chance to make some corrections to my previous post. I've used a more elegant approach to get round the json.h 'issue' I hadn't thought before when I've just chosen the quick and dirty approach. Instead of having to edit the sources to reflect the right json.h location, I've just defined the CFLAGS environment variable like this:

export CFLAGS=-I/usr/include/json-c/

without needing to edit anything. For what concerns the toolchain, there is a smarter approach if you're interested in the toolchain only. After the make menuconfig stage (as already explained, needed only to choose the right target), instead of just issuing the make command, it's much better to do:

make toolchain/install

and after a while you would find the toolchain under

openwrt/staging_dir/

If you like easy things, just go here:

https://archive.openwrt.org/releases/

select the proper version and target and just download the SDK, at the bottom of the list under ' Supplementary Files', extract the downloaded package and there you would find a ready to use toolchain, still under staging_dir.
I wish a nice day to everyone! :slight_smile: