pthreads for compiling with gcc?
-
I've got an Omega2+ running great, with a microSD card (overlay) file system, updated to the latest firmware. I've made good progress using opkg for installing various apps, but I'm failing in building cgminer from source because it can't find pthreads.
checking for pthread_create in -lpthread... no
configure: error: Could not find pthread library - please install libpthreadBut libpthread is already there.
root@Omega-808B:~/software/cgminer/cgminer-master# opkg install libpthread
Package libpthread (1.1.16-1) installed in root is up to date.Suggestions?
I'm currently setting up cross-compiling in case that helps, but this should work on the device. Shouldn't it?
-
I have used pthreads myself in one of my programs here.
On the Omega2 itself the compiler does not require the
-lpthread
switch. It will happily compile the program without it.Test program:
#include <stdio.h> #include <stdlib.h> #include <pthread.h> void* otherThread(void* arg) { printf("Hello world from other thread!\n"); return NULL; } int main(int argc, char* argv[]) { pthread_t t; printf("Spawning thread.\n"); pthread_create(&t, NULL, otherThread, NULL); pthread_join(t, NULL); printf("Program end.\n"); return 0; }
Compiles with
root@Omega-17FD:~# gcc -o pthread_test pthread_test.c root@Omega-17FD:~# ./pthread_test Spawning thread. Hello world from other thread! Program end.
If you give it the
-lpthread
switch it will sayroot@Omega-17FD:~# gcc -o pthread_test pthread_test.c -lpthread /usr/bin/ld: cannot find -lpthread collect2: error: ld returned 1 exit status
When doing cross-compilation however, the
-lpthread
switch is needed. (example)So, you might have success when you either cross-compile with the
-lpthread
switch or compile locally by removing the-lpthread
switches and checks.
-
Unfortunately, that isn't working. The app I'm building uses automake. I get the error when running ./configure.
If I remove the "-lpthread" argument, the error moves down the pipeline:
checking for pthread_create in -lpthread... no
configure: error: Could not find pthread library - please install libpthread
despite
root@Omega-808B:~/software/cgminer/cgminer-master# opkg install libpthread
Package libpthread (1.1.16-1) installed in root is up to date.Sigh. I'm not having luck cross-compiling either. Seems curl is using a version of libcurl that is out of date for my app. =(
-
@Joe-Andrieu After a long struggle, I was able to get it to compile with a mix of local compilation and cross compilation.
Basically:
- Install dependencies
opkg update && opkg install libusb-1.0 unzip
- Compile libcurl on the Omega2 from https://curl.haxx.se/download/curl-7.57.0.zip
- Cross-Compile libusb from https://github.com/libusb/libusb
- Cross-Compile cgminer using configure command below
- Work around some cgminer's checks by supplying custom CFLAGS and LINKER flags for it and commenting out checks (my configure file: https://pastebin.com/w53CjvWC)
For curl I had to build without SSL support since it didn't want to find OpenSSL. You might retry with mbedTLS or something.
Build command fors cURL (on Omega)
wget https://curl.haxx.se/download/curl-7.57.0.zip unzip curl-7.57.0.zip ./configure make make install
For libusb (cross-compile)
./configure --host=mipsel-openwrt-linux make -j4
Make a folder
curl
inside the cgminer sources, copy in all contents of your compiled libcurl (e.g.scp root@192.168.1.131:/root/curl-7.57.0/lib/.libs/* .
)Then compile cgminer (using the local paths to your libcurl + libusb include folder and lib folder)
CFLAGS="-L/home/max/cgminer-4.10.0/curl -L/home/max/curl-7.57.0/lib/.libs -I/home/max/curl-7.57.0/include -L/home/max/libusb/libusb/.libs -I/home/max/libusb/libusb" LIBUSB_CFLAGS="-O2 -L/home/max/libusb/libusb -I/home/max/libusb/libusb" LIBUSB_LIBS="-lusb-1.0" ./configure --host=mipsel-openwrt-linux --without-udev --enable-bitforce make -j4
Which gives you
max@max-VirtualBox:~/cgminer-4.10.0$ file cgminer cgminer: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked, interpreter /lib/ld-musl-mipsel-sf.so.1, not stripped
Transfer to Omega2 via
scp
and execute..root@Omega-17FD:~# ./cgminer -h cgminer 4.10.0 Built with bitforce mining support. Usage: ./cgminer [-DlmpPqUouOchnV] Options for both config file and command line: --api-allow <arg> Allow API access only to the given list of [G:]IP[/Prefix] addresses[/subnets] --api-description <arg> Description placed in the API status header, default: cgminer version ...
Obviously is not fully enabled with every possible feature (and libcurl without SSL!) but I think you can start working from there.
- Install dependencies