Имеется cmake файл, не знаю правильно ли добавляю в неё зависимости библиотек. нужно добавить egl и glesv3. или glesv2. Вот cmake и вот как я добавил это.
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log
egl
)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} egl glesv3)
Выводит такую ошибку.
Caused by: Build command failed.
Error while executing process /home/cf/Android/Sdk/cmake/3.10.2.4988404/bin/ninja with arguments {-C /home/cf/programs/GameTest/app/.cxx/cmake/debug/armeabi-v7a native-lib}
ninja: Entering directory `/home/cf/programs/GameTest/app/.cxx/cmake/debug/armeabi-v7a'
[1/1] Linking CXX shared library /home/cf/programs/GameTest/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so
FAILED: /home/cf/programs/GameTest/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so
: && /home/cf/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=armv7-none-linux-androideabi19 --gcc-toolchain=/home/cf/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/cf/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++14 -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -shared -Wl,-soname,libnative-lib.so -o /home/cf/programs/GameTest/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so CMakeFiles/native-lib.dir/native-lib.cpp.o /home/cf/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/19/liblog.so -legl -lglesv3 -latomic -lm && :
/home/cf/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -legl
/home/cf/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lglesv3
/home/cf/programs/GameTest/app/src/main/cpp/native-lib.cpp:26: error: undefined reference to 'eglGetDisplay'
/home/cf/programs/GameTest/app/src/main/cpp/native-lib.cpp:32: error: undefined reference to 'eglInitialize'
/home/cf/programs/GameTest/app/src/main/cpp/native-lib.cpp:37: error: undefined reference to 'eglChooseConfig'
/home/cf/programs/GameTest/app/src/main/cpp/native-lib.cpp:41: error: undefined reference to 'eglCreateWindowSurface'
/home/cf/programs/GameTest/app/src/main/cpp/native-lib.cpp:46: error: undefined reference to 'eglCreateContext'
/home/cf/programs/GameTest/app/src/main/cpp/native-lib.cpp:50: error: undefined reference to 'eglMakeCurrent'
/home/cf/programs/GameTest/app/src/main/cpp/native-lib.cpp:61: error: undefined reference to 'ANativeWindow_fromSurface'
/home/cf/programs/GameTest/app/src/main/cpp/native-lib.cpp:63: error: undefined reference to 'ANativeWindow_getWidth'
/home/cf/programs/GameTest/app/src/main/cpp/native-lib.cpp:64: error: undefined reference to 'ANativeWindow_getHeight'
/home/cf/programs/GameTest/app/src/main/cpp/native-lib.cpp:68: error: undefined reference to 'eglSwapBuffers'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
at com.android.build.gradle.internal.cxx.process.ProcessOutputJunction.execute(ProcessOutputJunction.kt:79)
at com.android.build.gradle.internal.cxx.process.ProcessOutputJunction.execute(ProcessOutputJunction.kt:120)
at com.android.build.gradle.tasks.ExternalNativeBuildTask.executeProcessBatch(ExternalNativeBuildTask.java:471)
at com.android.build.gradle.tasks.ExternalNativeBuildTask.buildImpl(ExternalNativeBuildTask.java:207)
at com.android.build.gradle.tasks.ExternalNativeBuildTask.doTaskAction(ExternalNativeBuildTask.java:107)
at com.android.build.gradle.internal.tasks.NonIncrementalTask$taskAction$$inlined$recordTaskAction$1.invoke(AndroidVariantTask.kt:51)
at com.android.build.gradle.internal.tasks.NonIncrementalTask$taskAction$$inlined$recordTaskAction$1.invoke(AndroidVariantTask.kt:31)
at com.android.build.gradle.internal.tasks.Blocks.recordSpan(Blocks.java:91)
at com.android.build.gradle.internal.tasks.NonIncrementalTask.taskAction(NonIncrementalTask.kt:34)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:103)
... 178 more
видимо он не видит эти функции, потому что библиотеки не правильно в cmake написаны или заданы. Помогите пожалуйста. Я исправил так.
find_library(
egl-lib
EGL
)
find_library(
gles-lib
GLESv3
)
но он ещё ругается на это.
Caused by: org.gradle.internal.UncheckedException: Build command failed.
Error while executing process /home/cf/Android/Sdk/cmake/3.10.2.4988404/bin/ninja with arguments {-C /home/cf/programs/GameTest/app/.cxx/cmake/debug/armeabi-v7a native-lib}
ninja: Entering directory `/home/cf/programs/GameTest/app/.cxx/cmake/debug/armeabi-v7a'
[1/1] Linking CXX shared library /home/cf/programs/GameTest/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so
FAILED: /home/cf/programs/GameTest/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so
: && /home/cf/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=armv7-none-linux-androideabi19 --gcc-toolchain=/home/cf/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/cf/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++14 -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -shared -Wl,-soname,libnative-lib.so -o /home/cf/programs/GameTest/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so CMakeFiles/native-lib.dir/native-lib.cpp.o /home/cf/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/19/liblog.so /home/cf/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/19/libEGL.so /home/cf/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/19/libGLESv3.so -latomic -lm && :
/home/cf/programs/GameTest/app/src/main/cpp/native-lib.cpp:61: error: undefined reference to 'ANativeWindow_fromSurface'
/home/cf/programs/GameTest/app/src/main/cpp/native-lib.cpp:63: error: undefined reference to 'ANativeWindow_getWidth'
/home/cf/programs/GameTest/app/src/main/cpp/native-lib.cpp:64: error: undefined reference to 'ANativeWindow_getHeight'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Надо сделать такой cmake файл и всё заработает.
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log
)
find_library(
egl-lib
EGL
)
find_library(
gles-lib
GLESv3
)
find_library(
android-lib
android
)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} ${egl-lib} ${gles-lib} ${android-lib} )
Айфон мало держит заряд, разбираемся с проблемой вместе с AppLab
Перевод документов на английский язык: Важность и ключевые аспекты
Программа должна крутить куб на который наложена текстура
Есть переменная, которую получаю из класса (тип float): Class->floatVar Нужно вывести нормально с char
Нужно увеличить скорость хеширования sha256 через pythonСтандартный hashlib работает через CPU
Я хотел бы создать экземпляр класса с обобщением, используя в качестве обобщения тип этого класса