ublk-org / ublksrv

ublk: userspace block device driver
MIT License
147 stars 50 forks source link

Cannot link to pthread #35

Closed old-memories closed 1 year ago

old-memories commented 1 year ago

Hi, although https://github.com/ming1/ubdsrv/issues/12 is helpful, I encountered the same problem again after I installed autoconf-archive. I used ./build_with_liburing_src to build ubdsrv. But the linker could not find pthread. See:

libtool: link: gcc -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000 -pthread -I/root/liburing-liburing-2.2/src/include -g -O0 -o .libs/demo_event demo_event-demo_event.o -L/root/liburing-liburing-2.2/src lib/.libs/libublksrv.so -L/usr/lib -luring -pthread -Wl,-rpath -Wl,/usr/local/lib mv -f qcow2/.deps/ublk-qcow2_flush_meta.Tpo qcow2/.deps/ublk-qcow2_flush_meta.Po /bin/sh ./libtool --tag=CXX --mode=link g++ -fcoroutines -std=c++20 -I/root/liburing-liburing-2.2/src/include -g -O0 -L/root/liburing-liburing-2.2/src -o ublk ublk-ublksrv_tgt.o ublk-tgt_null.o ublk-tgt_loop.o qcow2/ublk-tgt_qcow2.o qcow2/ublk-qcow2.o qcow2/ublk-qcow2_meta.o qcow2/ublk-utils.o qcow2/ublk-qcow2_flush_meta.o lib/libublksrv.la -L/usr/lib -luring libtool: link: g++ -fcoroutines -std=c++20 -I/root/liburing-liburing-2.2/src/include -g -O0 -o .libs/ublk ublk-ublksrv_tgt.o ublk-tgt_null.o ublk-tgt_loop.o qcow2/ublk-tgt_qcow2.o qcow2/ublk-qcow2.o qcow2/ublk-qcow2_meta.o qcow2/ublk-utils.o qcow2/ublk-qcow2_flush_meta.o -L/root/liburing-liburing-2.2/src lib/.libs/libublksrv.so -L/usr/lib -luring -Wl,-rpath -Wl,/usr/local/lib /usr/bin/ld: ublk-ublksrv_tgt.o: in function ublksrv_drain_fetch_commands(ublksrv_dev*, ublksrv_queue_info*)': /root/ubdsrv/ublksrv_tgt.cpp:262: undefined reference topthread_join' /usr/bin/ld: ublk-ublksrv_tgt.o: in function ublksrv_io_handler(void*)': /root/ubdsrv/ublksrv_tgt.cpp:298: undefined reference topthread_create' /usr/bin/ld: lib/.libs/libublksrv.so: undefined reference to pthread_spin_init' /usr/bin/ld: lib/.libs/libublksrv.so: undefined reference topthread_spin_unlock' /usr/bin/ld: lib/.libs/libublksrv.so: undefined reference to pthread_spin_lock' /usr/bin/ld: lib/.libs/libublksrv.so: undefined reference topthread_setaffinity_np' collect2: error: ld returned 1 exit status

Looks like -lpthread is missing. So I edited build_with_liburing_src:

LDFLAGS="-L${LIBURING_DIR}/src -lpthread"

Then I ran build_with_liburing_src again. And the build succeeded.

ming1 commented 1 year ago

It is one issue in ax_pthread.m4 in your distribution, can you test the following commit in fix-pthread-m4 branch and see if the issue can be fixed:

c3a805a configure.ac: ship one good ax_pthread.m4

https://github.com/ming1/ubdsrv/commit/c3a805aa9ed6aee43634938f9bf5d7fee04cff3e

Thanks,

old-memories commented 1 year ago

This works! Thanks, Ming. The version of ax_pthread.m4 in my distribution is 24 and it is too old.