libuv / help

Need help with libuv? Post your question here.
28 stars 7 forks source link

Andoid build: cannot find -lpthread #74

Closed distributed closed 5 years ago

distributed commented 5 years ago

In a project at work, I have libuv integrated as a git submodule. In the parent CMakeLists.txt I add an add_subdirectory(libuv) and then refer to the libuv target.

The build works fine for Linux, but linking fails when building for Adnroid: ...aarch64-linux-android/bin/ld: cannot find -lpthread. The full invocation and error message is below.

On Android, the pthread implementation is part of the Bionic C standard library, thus there is no libpthread.so and -lpthread should not be given.

By adding

  if(NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
    list(APPEND uv_libraries pthread)
  endif()

to the main CMakeLists.txt, I am able to circumvent the problem.

However I am surprised that this fix is necessary when Android is an official port of the library. I suppose that I am doing something wrong.

Any ideas what I am doing wrong?

Full invoation and error message:

[65/156] Linking C shared library src/3rdparty/libuv/libuv.so
FAILED: src/3rdparty/libuv/libuv.so 
: && /ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=aarch64-none-linux-android --gcc-toolchain=/ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 --sysroot=/ndk/sysroot -fPIC -isystem /ndk/sysroot/usr/include/aarch64-linux-android -D__ANDROID_API__=24 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security  -O2 -DNDEBUG  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot /ndk/platforms/android-24/arch-arm64 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -L/ndk/sources/cxx-stl/llvm-libc++/libs/arm64-v8a -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libuv.so -o src/3rdparty/libuv/libuv.so src/3rdparty/libuv/CMakeFiles/uv.dir/src/fs-poll.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/idna.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/inet.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/threadpool.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/timer.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/uv-common.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/uv-data-getter-setters.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/version.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/async.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/core.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/dl.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/fs.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/getaddrinfo.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/getnameinfo.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/loop-watcher.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/loop.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/pipe.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/poll.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/process.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/signal.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/stream.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/tcp.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/thread.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/tty.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/udp.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/android-ifaddrs.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/linux-core.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/linux-inotify.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/linux-syscalls.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/procfs-exepath.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/pthread-fixes.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/sysinfo-loadavg.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/sysinfo-memory.c.o src/3rdparty/libuv/CMakeFiles/uv.dir/src/unix/proctitle.c.o  -lpthread -latomic -lm && :
/ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lpthread
bnoordhuis commented 5 years ago

However I am surprised that this fix is necessary when Android is an official port of the library.

What makes you think that? Take a look at SUPPORTED_PLATFORMS.md, Android is a tier 3 platform, i.e., it's entirely community maintained. In other words: if it works, great! If it doesn't, send a PR. :-)

distributed commented 5 years ago

Thanks, I missed the tiered support statement document :) I'll send a PR.

distributed commented 5 years ago

Said PR is at https://github.com/libuv/libuv/pull/2110. I will close now.