Where are libpthread and librt on target?

Hello! I'm trying to compile some custom code on device which links to libpthread and librt.
Unfortunately, there seems to be no such files in the system, despite opkg says both libpthread and librt are installed.

I checked these packages:

opkg files libpthread

which shows 0 files, same for librt. The only pthread-related file is a header in /usr/include/pthread.h
Is this a limitation of musl libc library? Is it possible to switch to full glibc in a custom build? If not, what will be a compatible linking command for musl?

I'm running OpenWrt 19.07.5 on Xiaomi MIR3G (MediaTek MT7621)


1 Like

Thanks! probably need to introduce empty stubs in libpthread / librt packages to avoid confusion and linking errors

These empty stubs would just take space for no purpose. Since we do not officially support on-target compilation, it makes no sense at all to ship static library stubs. For the same reason we're not shipping header files etc.

Ok, thanks for the help. Is there a thread / some notes on native compilation?
I would need to do it to use some python libraries available through pip, which are
unlikely to be ported to routers. Setting a buildroot with pip seems more pain than
figuring out native compilation
Another issue I'm facing now are correct headers for floating point operations

Here you are mistaken, OpenWrt isn't built with native compilation in mind at all - sure, you could retrofit that, at which point you'd be very intimately familiar with buildroot (packaging up a couple of python packages for buildroot is peanuts in comparison).

1 Like

Ok, looks like this was easier than I thought. Did not test if the code works, but at least it compiles. Here is an instruction how to compile Numpy 1.19.4 natively

  1. First, you will need to mount large storage instead of the built in (extroot), as described here
  2. Make a swap file and mount it
dd if=/dev/zero of=/root/swap bs=1M count=2048
mkswap /root/swap
swapon /root/swap
  1. install everything you may need for building
opkg install python3 python-pip git bash gcc make coreutils-install 
  1. Login with bash (preferable make a general, non-root user)
  1. make stubs for missing pthreads and librt
ar -rc /usr/lib/libpthread.a
ar -rc /usr/lib/librt.a
  1. Edit the /usr/include/bits/fenv.h header
//#ifdef __mips_soft_float
//#define FE_ALL_EXCEPT 0
//#define FE_TONEAREST  0

This needs testing, I don't know if all fp exceptions work correctly in Numpy
7) set pip temporary locations to your large storage, otherwise it will overflow RAM:

export PIP_CACHE_DIR=/some/place/.cache
export TMP=/other/place/tmp

After that, type

pip install numpy 

get a large mug of coffee and be patient :slight_smile:

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.