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
Cross-Compiling libgit2 for Android: cannot find -lrt #2128
Comments
It sounds like this would be a good fix for the library. Can you submit that change as a pull request? That way you can make sure it works, and you'll get credit for the fix. 😄 One suggestion to avoid the nested ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT CMAKE_SYSTEM_VERSION MATCHES "Android")
TARGET_LINK_LIBRARIES(${target} rt)
SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lrt" PARENT_SCOPE)
ENDIF() |
Actually, I'd rather detach this check from matching the OS and instead directly test if we need diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6f2a2bb..723518a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -78,7 +78,10 @@ FUNCTION(TARGET_OS_LIBRARIES target)
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
TARGET_LINK_LIBRARIES(${target} socket nsl)
SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lsocket -lnsl" PARENT_SCOPE)
- ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
+ ENDIF()
+
+ CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" NEED_LIBRT)
+ IF(NEED_LIBRT)
TARGET_LINK_LIBRARIES(${target} rt)
SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lrt" PARENT_SCOPE)
ENDIF() I didn't actually test that on Android, but I think it might work. |
I just created a pull request. |
@worblehat Looks good. Let's make sure that the tests all pass on your Pull Request (Travis CI will run them for us and label the PR - you don't have to do anything), but it seems fine to me. |
Okay @worblehat - I merged your pull request. Thanks for putting it together. ✨ |
@xtao I remember we have the same |
I'd like to use libgit2 in an Android application. So I followed the build instuctions in README.md. I generated an arm standalone toolchain for the NDK and created the toolchain CMake-file. When building libgit2 I get an error, because the linker can't find librt:
I don't know much about librt, but as far as I understand, the NDK does not include librt, but instead integrates some of it's functionality in Android's libc.
So my approach to handle this error, was to edit CMakelists.txt, to not link to librt when CMAKE_SYSTEM_VERSION is set to "Android":
This compiled without problems and I can actually link to the libgit2.so in my Android App.
I don't have any experience with libgit2 and NDK, so I don't really know if this is the right way or if this will cause any problems. What do you think?
The text was updated successfully, but these errors were encountered: