gpt4 book ai didi

android - 将SDL2添加到android项目时dlopen失败(返回NULL)

转载 作者:搜寻专家 更新时间:2023-11-01 08:18:11 24 4
gpt4 key购买 nike

我在 Android Studio3.4 上使用 cmake3.6(NDK19)SDL2.0.9 添加到我的 Android 项目中,但出现此错误:

" E/SDL: nativeRunMain(): Couldn't load library /data/app/org.libsdl.app-eOed871MljqNS6cZDl_DBg==/lib/arm64/libmain.so"

调试后,在SDL2/src/core/androd/SDL_android.c中发现了这一行(library_handle is NULL):

library_handle = dlopen(library_file, RTLD_GLOBAL);
if (library_handle) {
...
} else {
__android_log_print(ANDROID_LOG_ERROR, "SDL", "nativeRunMain(): Couldn't load library %s", library_file);
}

下面是我的CMakeLists.txt:

cmake_minimum_required(VERSION 3.4.1)

file(GLOB my_source ${CMAKE_SOURCE_DIR}/*.cpp ${CMAKE_SOURCE_DIR}/*.c)

add_library(main
SHARED
main.cpp)

include_directories(${CMAKE_SOURCE_DIR}/include)

add_subdirectory(${CMAKE_SOURCE_DIR}/SDL2)
include_directories(${CMAKE_SOURCE_DIR}/SDL2/include)

find_library(log-lib
log)

target_link_libraries(
main
SDL2
GLESv1_CM
GLESv2
-landroid
${log-lib})

和我的ma​​in.cpp:

#include <android/log.h>

#define LOG_TAG "gmyffplay"
#define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))

#include "SDL.h"

extern "C" {

int main(int argc, char *argv[]) {

char *video_path = argv[1];
LOGI("video_path : %s", video_path);

SDL_Window *window;
SDL_Renderer *renderer;
SDL_Event event;

if (SDL_Init(SDL_INIT_VIDEO) < 0) {
LOGE("Could not initialize SDL - %s", SDL_GetError());
return 1;
}

window = SDL_CreateWindow("SDL_Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 0, 0,
SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(window, -1, 0);
SDL_Surface *bmp = SDL_LoadBMP("image.bmp");
SDL_SetColorKey(bmp, SDL_TRUE, 0xffffff);
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, bmp);
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
while (1) {
if (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
break;
}
}
SDL_SetRenderDrawColor(renderer, 0, 133, 119, 255);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
SDL_FreeSurface(bmp);
SDL_DestroyTexture(texture);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
}

我确定 library_file 存在,apk 中的 libmain.so 和 libSDL2 在 libmain.so 之前加载。

谁能帮助我,将不胜感激

编辑:

这是我的项目架构

enter image description here

最佳答案

我在 android-ndk github issues 上找到了解决方案, 似乎在查找用于动态链接 libdl.so 库的库时出现问题,其中声明了 dlopen 函数。

所以你需要改变:
find_library(ANDROID_DL_LIBRARY dl)
find_library(ANDROID_DL_LIBRARY NAMES libdl.so dl)SDL2/CMakeLists.txt

关于android - 将SDL2添加到android项目时dlopen失败(返回NULL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55804006/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com