Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot link to pthread #35

Closed
old-memories opened this issue Nov 24, 2022 · 2 comments
Closed

Cannot link to pthread #35

old-memories opened this issue Nov 24, 2022 · 2 comments

Comments

@old-memories
Copy link
Contributor

old-memories commented Nov 24, 2022

Hi, although #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 to pthread_join'
/usr/bin/ld: ublk-ublksrv_tgt.o: in function ublksrv_io_handler(void*)': /root/ubdsrv/ublksrv_tgt.cpp:298: undefined reference to pthread_create'
/usr/bin/ld: lib/.libs/libublksrv.so: undefined reference to pthread_spin_init' /usr/bin/ld: lib/.libs/libublksrv.so: undefined reference to pthread_spin_unlock'
/usr/bin/ld: lib/.libs/libublksrv.so: undefined reference to pthread_spin_lock' /usr/bin/ld: lib/.libs/libublksrv.so: undefined reference to pthread_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
Copy link
Collaborator

ming1 commented Nov 24, 2022

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

c3a805a

Thanks,

@old-memories
Copy link
Contributor Author

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

ming1 added a commit that referenced this issue Nov 26, 2022
It is reported that on some distributions ax_pthread.m4 in
autoconf-archive package doesn't work as expected.

Address issue #35.

Reported-by: ZiyangZhang <ZiyangZhang@linux.alibaba.com>
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
@ming1 ming1 closed this as completed Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants