Why openwrt can't find library path even if they are installed

Hi all,

I am trying to natively compile a file in openwrt which doesn't work if of course libraries are not installed. My package depends on ixwebsocket, which I correctly managed to install, but when I perform a command like:
gcc prova.cpp -std=c++17 -lstdc++ -lssl -lixwebsocket -lpthread -lcrypto -o web_ex

The message is:
/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -lcrypto
collect2: error: ld returned 1 exit status

So I added the path in PATH and $LD_LIBRARY_PATH given the fact that these libraries exist in /usr/lib, same error.

If I generate empty dummy archive files (libssl.a,libcrypto.a,..) than the compilation continues which looks really weird to me. Also the program complains about libz which as well is installed and has the corresponding archive here: /usr/lib/libz.a, dumping a series of errors which are:
IXGzipCodec.cpp:(.text+0x1b0): undefined reference to inflateInit2_' IXGzipCodec.cpp:(.text+0x1e4): undefined reference to inflate'
IXGzipCodec.cpp:(.text+0x1fc): undefined reference to `inflateEnd'

So my questions are 2:

1 - It looks to me really hacky solution create an empty archive, why this is working?
2 - Why I get the libz.a error? My best guest is that the ixwebsocket library hasn't been built with it, but on my local machine I don't get the error and the cmake cache files are the same of local machine and crosscompilation.

It is really frustrating issue, is someone could help I would appreciate.


I don't think libssl.so and libcrypto.so exists, which are the files it will look for. Usually they are symbolic links, but I don't know if it works if you make links from the existing version of those libraries.

In general you are supposed to build openwrt packages on another system using the SDK (or using a complete build tree).

Hi mikma,

Thanks for coming back to me. They are shared libraries, unless I am missing something, they should exist. Indeed looking into openwrt in the modem:

-rw-r--r-- 1 root root 268135 Feb 27 2020 libssl.so.1.0.0
-rw-r--r-- 1 root root 1166575 Feb 27 2020 libcrypto.so.1.0.0

You are right, I should crosscompile and I managed as well via that procedure to get the package. The problem here is that I can't get ixwebsocket to connect when I run it. I need to understand if I am compiling it in a wrong way as I can't connect through PORT 443, which, after having tested with curl looks open. I 'd like to give a shot via native compilation of a basic file for debugging purpose.


When building with "-lssl -lcrypto" it will look for libssl.so and libcrypto.so.

The names above, are the SONAMEs which are used during run time.

Yes indeed, that is why I was linking them using -l and omitting the prefix. At the end of the day I found what the mistake was, I needed also to link with -lz when I was cross-compiling the package for openwrt therefore I didn't investigate further about native compiling. Thanks anyway for your time!

You shouldn't be using HOST libraries in the build system.

If you are trying to compile a package that includes those libs, check your ./configure (if available) for flags to set flags for:


Which are built into the build environment.

Alternative, you can put the toolchain path into your environment/command line..

./staging_dir/toolchain-<TARGET>_gcc-10.2.0_musl/lib and ./staging_dir/toolchain-<TARGET>_gcc-10.2.0_musl/include

Your build system shouldn't be looking for libs in /usr/lib. Those are for your host architecture, not the target.