OiO.lk Blog Android Why is __android_log_print undefined?
Android

Why is __android_log_print undefined?


When I try to add android_native_app_glue.c to my Android CMake project I get the following error when building.

ld: error: undefined symbol: __android_log_print
>>> referenced by android_native_app_glue.c:51 (C:/dev/android/sdk/ndk/22.1.7171670/sources/android/native_app_glue\android_native_app_glue.c:51)
>>>               CMakeFiles/app-glue.dir/C_/dev/android/sdk/ndk/22.1.7171670/sources/android/native_app_glue/android_native_app_glue.c.o:(android_app_read_cmd)

Here is my CMakeLists.txt file.

cmake_minimum_required(VERSION 3.22.1)
project(MyGame)

set (APP_GLUE_DIR ${ANDROID_NDK}/sources/android/native_app_glue)

add_library(app-glue SHARED ${APP_GLUE_DIR}/android_native_app_glue.c)
target_include_directories(app-glue PUBLIC ${APP_GLUE_DIR})

add_library(native-lib SHARED ./native-lib.cpp)
target_include_directories(native-lib PUBLIC ${APP_GLUE_DIR})

add_library(libMyGame SHARED IMPORTED )

find_library(log-lib log)

set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
target_link_libraries(native-lib app-glue android ${log-lib} libMyGame)

Why is this linker error occurring and how can I fix it? Note that native-lib also uses __android_log_print but there are no similar errors for that.



You need to sign in to view this answers

Exit mobile version