Я пишу приложение на C++, использующее SDL2.
Я добавил заголовки в каталог app/cpp/include проекта.
Я также скачал исходный код с Github и скомпилировал его в общий объект Android, но не могу заставить компоновщик в Android Studio его найти.
Решения online предлагают создать папку jniLibs в каталоге приложения и поместить туда все общие объекты, но это не работает.
Это мой CMakeList.txt файл:
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/a ... -code.html.
# For more examples on how to use CMake, see https://github.com/android/ndk-samples.
# Sets the minimum CMake version required for this project.
cmake_minimum_required(VERSION 3.22.1)
# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
# Since this is the top level CMakeLists.txt, the project name is also accessible
# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
# build script scope).
project("easynes_android")
# 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.
#
# In this top level CMakeLists.txt, ${CMAKE_PROJECT_NAME} is used to define
# the target library name; in the sub-module's CMakeLists.txt, ${PROJECT_NAME}
# is preferred for the same purpose.
#
# In order to load a library into your app from Java/Kotlin, you must call
# System.loadLibrary() and pass the name of the library defined here;
# for GameActivity/NativeActivity derived applications, the same library name must be
# used in the AndroidManifest.xml file.
# Find all .cpp files in the current directory
file(GLOB CPP_SOURCE_FILES "*.cpp")
# Find all .c files in the current directory
file(GLOB C_SOURCE_FILES "*.c")
# Combine the lists of .cpp and .c files
set(SOURCE_FILES ${CPP_SOURCE_FILES} ${C_SOURCE_FILES})
# Add the library using the collected source files
add_library(${CMAKE_PROJECT_NAME} SHARED ${SOURCE_FILES})
# Specifies libraries CMake should link to your target library. You
# can link libraries from various origins, such as libraries defined in this
# build script, prebuilt third-party libraries, or Android system libraries.
target_link_libraries(${CMAKE_PROJECT_NAME}
# List libraries link to the target library
android
log
libSDL2.so)
Папка jniLibs выглядит следующим образом:
.../app/jniLibs
--->arm64-v8a
-------> libSDL2.so
--->armeabi-v7a
-------> libSDL2.so
etc...
Заранее спасибо
РЕДАКТИРОВАТЬ:
Это ошибка, которую я получаю:
[1/1] Linking CXX shared library /home/roeet/AndroidStudioProjects/easynesandroid/app/build/intermediates/cxx/Debug/15i4x120/obj/x86_64/libeasynes_android.so
FAILED: /home/roeet/AndroidStudioProjects/easynesandroid/app/build/intermediates/cxx/Debug/15i4x120/obj/x86_64/libeasynes_android.so
: && /home/roeet/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=x86_64-none-linux-android21 --sysroot=/home/roeet/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -std=c++17 -fno-limit-debug-info -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Wl,--gc-sections -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libeasynes_android.so -o /home/roeet/AndroidStudioProjects/easynesandroid/app/build/intermediates/cxx/Debug/15i4x120/obj/x86_64/libeasynes_android.so CMakeFiles/easynes_android.dir/apu.cpp.o CMakeFiles/easynes_android.dir/bus.cpp.o CMakeFiles/easynes_android.dir/cnrom_3.cpp.o CMakeFiles/easynes_android.dir/controller.cpp.o CMakeFiles/easynes_android.dir/cpu.cpp.o CMakeFiles/easynes_android.dir/instructions.cpp.o CMakeFiles/easynes_android.dir/mapper_n_cart.cpp.o CMakeFiles/easynes_android.dir/mmc1_1.cpp.o CMakeFiles/easynes_android.dir/mmc3_4.cpp.o CMakeFiles/easynes_android.dir/native-lib.cpp.o CMakeFiles/easynes_android.dir/nes_screen.cpp.o CMakeFiles/easynes_android.dir/nrom_0.cpp.o CMakeFiles/easynes_android.dir/ppu.cpp.o CMakeFiles/easynes_android.dir/unrom_2.cpp.o CMakeFiles/easynes_android.dir/utils.cpp.o -landroid -llog -lSDL2 -latomic -lm && :
ld: error: unable to find library -lSDL2
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Подробнее здесь: https://stackoverflow.com/questions/785 ... oid-studio
Связывание внешнего общего объекта в Android Studio ⇐ C++
Программы на C++. Форум разработчиков
-
Anonymous
1716587334
Anonymous
Я пишу приложение на C++, использующее SDL2.
Я добавил заголовки в каталог app/cpp/include проекта.
Я также скачал исходный код с Github и скомпилировал его в общий объект Android, но не могу заставить компоновщик в Android Studio его найти.
Решения online предлагают создать папку jniLibs в каталоге приложения и поместить туда все общие объекты, но это не работает.
Это мой CMakeList.txt файл:
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html.
# For more examples on how to use CMake, see https://github.com/android/ndk-samples.
# Sets the minimum CMake version required for this project.
cmake_minimum_required(VERSION 3.22.1)
# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
# Since this is the top level CMakeLists.txt, the project name is also accessible
# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
# build script scope).
project("easynes_android")
# 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.
#
# In this top level CMakeLists.txt, ${CMAKE_PROJECT_NAME} is used to define
# the target library name; in the sub-module's CMakeLists.txt, ${PROJECT_NAME}
# is preferred for the same purpose.
#
# In order to load a library into your app from Java/Kotlin, you must call
# System.loadLibrary() and pass the name of the library defined here;
# for GameActivity/NativeActivity derived applications, the same library name must be
# used in the AndroidManifest.xml file.
# Find all .cpp files in the current directory
file(GLOB CPP_SOURCE_FILES "*.cpp")
# Find all .c files in the current directory
file(GLOB C_SOURCE_FILES "*.c")
# Combine the lists of .cpp and .c files
set(SOURCE_FILES ${CPP_SOURCE_FILES} ${C_SOURCE_FILES})
# Add the library using the collected source files
add_library(${CMAKE_PROJECT_NAME} SHARED ${SOURCE_FILES})
# Specifies libraries CMake should link to your target library. You
# can link libraries from various origins, such as libraries defined in this
# build script, prebuilt third-party libraries, or Android system libraries.
target_link_libraries(${CMAKE_PROJECT_NAME}
# List libraries link to the target library
android
log
libSDL2.so)
Папка jniLibs выглядит следующим образом:
.../app/jniLibs
--->arm64-v8a
-------> libSDL2.so
--->armeabi-v7a
-------> libSDL2.so
etc...
Заранее спасибо
РЕДАКТИРОВАТЬ:
Это ошибка, которую я получаю:
[1/1] Linking CXX shared library /home/roeet/AndroidStudioProjects/easynesandroid/app/build/intermediates/cxx/Debug/15i4x120/obj/x86_64/libeasynes_android.so
FAILED: /home/roeet/AndroidStudioProjects/easynesandroid/app/build/intermediates/cxx/Debug/15i4x120/obj/x86_64/libeasynes_android.so
: && /home/roeet/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=x86_64-none-linux-android21 --sysroot=/home/roeet/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -std=c++17 -fno-limit-debug-info -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Wl,--gc-sections -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libeasynes_android.so -o /home/roeet/AndroidStudioProjects/easynesandroid/app/build/intermediates/cxx/Debug/15i4x120/obj/x86_64/libeasynes_android.so CMakeFiles/easynes_android.dir/apu.cpp.o CMakeFiles/easynes_android.dir/bus.cpp.o CMakeFiles/easynes_android.dir/cnrom_3.cpp.o CMakeFiles/easynes_android.dir/controller.cpp.o CMakeFiles/easynes_android.dir/cpu.cpp.o CMakeFiles/easynes_android.dir/instructions.cpp.o CMakeFiles/easynes_android.dir/mapper_n_cart.cpp.o CMakeFiles/easynes_android.dir/mmc1_1.cpp.o CMakeFiles/easynes_android.dir/mmc3_4.cpp.o CMakeFiles/easynes_android.dir/native-lib.cpp.o CMakeFiles/easynes_android.dir/nes_screen.cpp.o CMakeFiles/easynes_android.dir/nrom_0.cpp.o CMakeFiles/easynes_android.dir/ppu.cpp.o CMakeFiles/easynes_android.dir/unrom_2.cpp.o CMakeFiles/easynes_android.dir/utils.cpp.o -landroid -llog -lSDL2 -latomic -lm && :
ld: error: unable to find library -lSDL2
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Подробнее здесь: [url]https://stackoverflow.com/questions/78530523/linking-an-external-shared-object-in-android-studio[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия