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

Fix build error on Android #212

Merged
merged 1 commit into from
Nov 3, 2023
Merged

Conversation

ysohma
Copy link
Contributor

@ysohma ysohma commented Oct 23, 2023

Hi there,

I'm encountering a build error on the Android platform.

In contrib/CMakeLists.txt, the -lpthread linker flag is added for non-Windows platforms. However, on certain platforms like Android, the -lpthread flag is unnecessary and is causing build errors.

This is simple script to reproduce.

mkdir _build
cd _build
cmake -DCMAKE_TOOLCHAIN_FILE=<NDK-path>/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a ../contrib
cmake --build .

# [  5%] Building CXX object 
# CMakeFiles/eight_bit_int_gemm.dir/Users/yoshio.soma/gemmlowp/eight_bit_int_gemm/eight_bit_int_gemm.cc.o
# [ 11%] Linking CXX static library libeight_bit_int_gemm.a
# [ 11%] Built target eight_bit_int_gemm
# [ 17%] Building CXX object CMakeFiles/benchmark.dir/Users/yoshio.soma/gemmlowp/test/benchmark.cc.o
# [ 23%] Linking CXX executable benchmark
# ld: error: unable to find library -lpthread
# clang++: error: linker command failed with exit code 1 (use -v to see invocation)
# make[2]: *** [benchmark] Error 1
# make[1]: *** [CMakeFiles/benchmark.dir/all] Error 2
# make: *** [all] Error 2

Changes

Instead of hard-coding the -lpthread flag, I propose using find_package() to link with pthread. By employing find_package(), CMake will automatically detect the platform and set the appropriate flags accordingly.

Related Issue

I believe this change will resolve the build error on the Android platform. Your feedback and review are much appreciated.

Thank you!

@ysohma ysohma marked this pull request as ready for review October 23, 2023 05:47
@wowo68
Copy link

wowo68 commented Oct 23, 2023 via email

@bjacob
Copy link
Contributor

bjacob commented Oct 23, 2023

Thanks for the PR. It seems reasonable. I don't seem to have permissions anymore to merge PRs here, as I am no longer a Google employee. @mariecwhite can you take a look? No need to import this into the Google internal code repository (a manual process anyway, no copybara here). This should be GitHub-only - just merge this PR here.

@mariecwhite
Copy link
Collaborator

Looks like I don't have permissions to merge here. Let me see if I can get write access.

@mariecwhite mariecwhite merged commit 16e8662 into google:master Nov 3, 2023
1 check passed
@mariecwhite
Copy link
Collaborator

I now have write access. PR merged.

@ysohma ysohma deleted the fix-pthread-link branch November 6, 2023 07:15
This pull request was closed.
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

Successfully merging this pull request may close these issues.

5 participants