Linked in libraries when cross-compiling
-
@WereCatf Hi,
I'm trying to cross-compile a source which needs libncurses. I've built the toolchain using the image branch of your repository github.com:werecatf/source.git and I can compile and run simple binaries.
But now, I'd like to build larger projects which depend on other software packages. I have the problem that the cross-compiler doesn't seem to respect library paths.
For example, I did this:
mdj@xxx:/tmp$ mipsel-openwrt-linux-gcc foo.c -L~/src/werecatf/staging_dir/target-mipsel_24kc_musl-1.1.15/usr/lib -lncursesw
/home/mdj/src/werecatf/staging_dir/toolchain-mipsel_24kc_gcc-5.4.0_musl-1.1.15/lib/gcc/mipsel-openwrt-linux-musl/5.4.0/../../../../mipsel-openwrt-linux-musl/bin/ld: cannot find -lncurseswWhat could be the problem, and what, in general, is the normal way to do this?
Best regards,
Mikael
-
@Mikael-Djurfeldt The library has been renamed to ncurses, not ncursesw, for compatibility-reasons.
-
@WereCatf In the directory that I gave with -L, there actually is a libncursesw.a, but it doesn't find it! Also, I've tried -lncurses...
-
@Mikael-Djurfeldt I'm not exactly a cross-compiling wizard myself, either, but here are the steps on how I compile a simple ncurses-based app. First, I use a small script called
cross.sh
at the root of the LEDE-sources to set up a cross-compiling environment for myself:#!/bin/bash pushd . pushd `dirname $0` > /dev/null export SCRIPTDIR=`pwd` popd > /dev/null cd $SCRIPTDIR cd staging_dir/toolchain* cd bin export PATH=$PATH:$(pwd) cd $SCRIPTDIR cd staging_dir export STAGING_DIR=$(pwd) cd target-* export TARGET_DIR=$(pwd) export CC=mips-openwrt-linux-gcc export LD=mips-openwrt-linux-ld export CROSS_COMPILE=mipsel-openwrt-linux- export CFLAGS="-march=24kec -mtune=24kec -mdsp -D_MIPS_ARCH_MIPS32R2" export CPPFLAGS="-I${TARGET_DIR}/usr/include" export LDFLAGS="-L${TARGET_DIR}/lib -L${TARGET_DIR}/usr/lib" popd bash
I create a file called curseshello.c:
#include <stdio.h> #include <ncurses.h> void main() { WINDOW *vin; initscr(); start_color(); init_pair(1,COLOR_YELLOW,COLOR_BLUE); init_pair(2,COLOR_BLUE,COLOR_YELLOW); init_pair(3,COLOR_BLUE,COLOR_WHITE); vin=newwin(12,40,13,0); wmove(vin,0,5); wprintw(vin,"Hello, World."); wbkgd(vin,COLOR_PAIR(1)); wrefresh(vin); getch(); delwin(vin); endwin(); }
Then I proceed to call the cross.sh and then compile the above code with:
mipsel-openwrt-linux-gcc $CFLAGS curseshello.c -o curseshello -lncurses $CPPFLAGS $LDFLAGS
A proper cross-compiling wizard would most likely be aghast at all the stupidity I commit here, but I only taught myself rudimentary cross-compiling like two-three weeks ago, and this method works for now, so...
-
@WereCatf Many thanks! I found the source of the problem: Tilde expansion doesn't work juxtaposed to -L. I just had to replace it with $HOME.
However, it strange that the tools don't respect LIBRARY_PATH---something I've also tested.
-
Hello,
May I ask you on which Linux Distribution you are cross compiling?
I have tried to build the tool chain (including the LEDE Image) on Kubuntu and on Ubuntu
without success by following this tutorial:https://wiki.onion.io/Tutorials/Cross-Compile
with the toolchain from the "Onion Omega2" branch from Onion's git hub
This is the error I am getting (on latest Ubuntu LTS):
There had also been a couple of errors before this one that I have managed to fix by recrusive chmodding the whole directory with 777.
-
@Adrian-Rix Sure---I built using the "image" branch of https://github.com/WereCatf/source.git on a Debian stretch system.
Basically, once you have checked that out, you can do just
make
to get the image, however you might want to select things using
make menuconfig
first.