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 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 -lncursesw

    What could be the problem, and what, in general, is the normal way to do this?

    Best regards,

  • @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 at the root of the LEDE-sources to set up a cross-compiling environment for myself:

    pushd .
    pushd `dirname $0` > /dev/null
    export SCRIPTDIR=`pwd`
    popd > /dev/null
    cd staging_dir/toolchain*
    cd bin
    export PATH=$PATH:$(pwd)
    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"

    I create a file called curseshello.c:

    #include <stdio.h>
    #include <ncurses.h>
    void main()
        WINDOW *vin;
        wprintw(vin,"Hello, World.");

    Then I proceed to call the 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:

    with the toolchain from the "Onion Omega2" branch from Onion's git hub

    This is the error I am getting (on latest Ubuntu LTS):

    Bild Text

    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 on a Debian stretch system.

    Basically, once you have checked that out, you can do just


    to get the image, however you might want to select things using

    make menuconfig


Log in to reply

Looks like your connection to Onion Community was lost, please wait while we try to reconnect.