Skip to content

Do not link to pthread when targeting Android #326

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

Merged
merged 1 commit into from
Mar 20, 2024

Conversation

aabajyan
Copy link
Contributor

@aabajyan aabajyan commented Mar 19, 2024

I had issues compiling this for Android, and as it turns out, pthread functionality is part of libc itself and linking is not required. If there's any issues let me know!
The error I got:

ld: error: unable to find library -lpthread
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@saghul
Copy link
Contributor

saghul commented Mar 19, 2024

How are you compiling it? Our CI does compile the library.

@aabajyan
Copy link
Contributor Author

aabajyan commented Mar 19, 2024

Yeah just noticed the android workflow. I think the reason has to do with BUILD_QJS_LIBC, because this I set this ON. There's not much here

 # QuickJS
 set(BUILD_QJS_LIBC ON CACHE BOOL "" FORCE)
 add_subdirectory(vendor/quickjs EXCLUDE_FROM_ALL)

@saghul
Copy link
Contributor

saghul commented Mar 19, 2024

I see. Can you please set that option (with -D) on our worlflow in order to actually test this?

CMakeLists.txt Outdated
@@ -155,7 +155,11 @@ endif()
list(APPEND qjs_defines _GNU_SOURCE)
list(APPEND qjs_libs qjs ${CMAKE_DL_LIBS})
if(NOT MSVC)
list(APPEND qjs_libs m pthread)
if (NOT ANDROID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this works, I think using CMAKE_THREAD_LIBS_INIT feels more future proof: https://cmake.org/cmake/help/latest/module/FindThreads.html

I had issues compiling this for Android, and as it turns out, pthread functionality
is part of Bionic itself and linking is not required.
@saghul saghul merged commit 48cb3ac into quickjs-ng:master Mar 20, 2024
@saghul
Copy link
Contributor

saghul commented Mar 20, 2024

Thank you!

@aabajyan aabajyan deleted the android-threads branch March 20, 2024 15:53
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.

2 participants