Skip to content

Conversation

@Phillip-Wang
Copy link
Contributor

Signed-off-by: Phil Wang [email protected]

Signed-off-by: Phil Wang <[email protected]>
@triplef
Copy link

triplef commented Aug 5, 2019

I tried out this branch with NDK r20, but it failed with the following error:
inc/NE10_types.h:39:10: fatal error: 'assert.h' file not found

Looking at the android_config.cmake and comparing the generated compiler flags with the ones from the NDK’s android.toolchain.cmake file, I think that sysroot was not being set correctly. The following change fixes the compilation for me.

diff --git a/android/android_config.cmake b/android/android_config.cmake
index 0ab89ef..f86cbc5 100644
--- a/android/android_config.cmake
+++ b/android/android_config.cmake
@@ -83,14 +83,12 @@ else()
 endif()
 
 #NDK_SYSROOT_PATH is used in compiler's '--sysroot' flags
-set(NDK_SYSROOT_PATH "$ENV{ANDROID_NDK}/platforms/android-${ANDROID_API_LEVEL}/arch-${ANDROID_NDK_PLATFORMS_ARCH_SUFFIX}/")
-set(NDK_ISYSROOT_PATH "$ENV{ANDROID_NDK}/sysroot -I$ENV{ANDROID_NDK}/sysroot/usr/include/${ANDROID_NDK_TOOLCHAIN_CROSS_PREFIX}")
-
 if(APPLE)
-    #TODO: Check whether this path is correct for aarch64 under mac.
     set(ANDROID_TOOLCHAIN_PATH "$ENV{ANDROID_NDK}/toolchains/llvm/prebuilt/darwin-x86_64/bin")
+    set(NDK_SYSROOT_PATH "$ENV{ANDROID_NDK}/toolchains/llvm/prebuilt/darwin-x86_64/sysroot")
 else()
     set(ANDROID_TOOLCHAIN_PATH "$ENV{ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin")
+    set(NDK_SYSROOT_PATH "$ENV{ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot")
 endif()
 
 #change toolchain name according to your configuration
@@ -122,7 +120,6 @@ endif()
 
 #TODO: Fine tune pic and pie flag for executable, share library and static library.
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${NDK_SYSROOT_PATH} -pie")
-string(APPEND CMAKE_C_FLAGS " -isysroot ${NDK_ISYSROOT_PATH}")
 # set(CMAKE_ASM_FLAGS "")
 add_definitions(-D__ANDROID_API__=${ANDROID_API_LEVEL})
 

Btw, is there any reason why Ne10 is not using the NDK’s CMake toolchain file as officially recommended?

@yunychen
Copy link

yunychen commented Jun 4, 2021

I tried out this branch with NDK r20, but it failed with the following error:
inc/NE10_types.h:39:10: fatal error: 'assert.h' file not found

Looking at the android_config.cmake and comparing the generated compiler flags with the ones from the NDK’s android.toolchain.cmake file, I think that sysroot was not being set correctly. The following change fixes the compilation for me.

diff --git a/android/android_config.cmake b/android/android_config.cmake
index 0ab89ef..f86cbc5 100644
--- a/android/android_config.cmake
+++ b/android/android_config.cmake
@@ -83,14 +83,12 @@ else()
 endif()
 
 #NDK_SYSROOT_PATH is used in compiler's '--sysroot' flags
-set(NDK_SYSROOT_PATH "$ENV{ANDROID_NDK}/platforms/android-${ANDROID_API_LEVEL}/arch-${ANDROID_NDK_PLATFORMS_ARCH_SUFFIX}/")
-set(NDK_ISYSROOT_PATH "$ENV{ANDROID_NDK}/sysroot -I$ENV{ANDROID_NDK}/sysroot/usr/include/${ANDROID_NDK_TOOLCHAIN_CROSS_PREFIX}")
-
 if(APPLE)
-    #TODO: Check whether this path is correct for aarch64 under mac.
     set(ANDROID_TOOLCHAIN_PATH "$ENV{ANDROID_NDK}/toolchains/llvm/prebuilt/darwin-x86_64/bin")
+    set(NDK_SYSROOT_PATH "$ENV{ANDROID_NDK}/toolchains/llvm/prebuilt/darwin-x86_64/sysroot")
 else()
     set(ANDROID_TOOLCHAIN_PATH "$ENV{ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin")
+    set(NDK_SYSROOT_PATH "$ENV{ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot")
 endif()
 
 #change toolchain name according to your configuration
@@ -122,7 +120,6 @@ endif()
 
 #TODO: Fine tune pic and pie flag for executable, share library and static library.
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${NDK_SYSROOT_PATH} -pie")
-string(APPEND CMAKE_C_FLAGS " -isysroot ${NDK_ISYSROOT_PATH}")
 # set(CMAKE_ASM_FLAGS "")
 add_definitions(-D__ANDROID_API__=${ANDROID_API_LEVEL})
 

Btw, is there any reason why Ne10 is not using the NDK’s CMake toolchain file as officially recommended?

hi triplef,
do you compile ok with NDK r20?

@peter-toft-greve
Copy link

I also see quite a bit of short-comings with the original ANDROID_PLATFORM code. The -pie is an issue with r20

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.

4 participants