/usr/bin/ld: cannot find -lpthread

Trying to build a Go program on OpenWRT but get the following error:

# runtime/cgo
/usr/bin/ld: cannot find -lpthread
collect2: error: ld returned 1 exit status

Been googling around but can't seem to find a solution. I suspect there's a library missing or something. Anyone have any ideas?

1 Like

https://openwrt.org/packages/pkgdata/libpthread -- installed?

Yeah it is. But there's no libpthread.so in /lib/ which I'm guessing there should be, so I tried uninstalling it (forced uninstall, because it's an essential package) and re-installed with opkg hoping it would add the .so file, but it didn't. So I've been searching for an answer but no luck so far. How can I create the .so file if it doesn't come with the package in opkg?

If I remember correctly, libpthread is integrated into musl libc.

Pthread primitives are part of the core libc.so library. To satisfy -lpthread, create an empty AR archive somewhere in the library search path.

E.g.: ar -rc /usr/lib/libpthread.a

4 Likes

Thank you @jow, that seems to have fixed it! :beers:

The Gocode I'm attempting to compile now throws me an error about pcap.h missing. I think that file is part of the libpcap dev package, other Linux distros e.g. Ubuntu have a package named libpcap0.8-dev which supposedly includes it. Opkg does have a libpcap package which I have installed already but apparently it lacks this header file. Is there any similar solution to satisfying this dependency?

Unfortunately not, OpenWrt does not provide development header packages via Opkg.

You either need to copy pcap.h from somewhere else or cross compile libpcap manually on OpenWrt

1 Like

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