gpt4 book ai didi

android - 即使包含,也无法创建 SDL_Window 给出 SDL_Main.h 错误

转载 作者:行者123 更新时间:2023-12-04 23:29:06 36 4
gpt4 key购买 nike

我正在尝试使用 FFMPEG(Fetching,decode.etc) 播放网络流,并尝试使用 SDL 渲染它。

当我运行我的应用程序时,它会正常启动,但只要我调用 OpenFile()其中包含用于打开网络流并创建 SDL_Window 和 SDL_Renderer 的代码,但它在 SDL_CreateWindow() 上给了我一个错误说:
Window not created: [Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?].
即使我已包含 SDL_main.h .

#include <SDL.h>
#include <SDL_main.h>
..... //other header files

#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)

SDL_Window *window;
SDL_Renderer *renderer;

int main(int argc, char *argv[])
{
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER))
{
LOGE("Could not initialize SDL - %s\n", SDL_GetError());
exit(1);
}
return 0;
}

void Java_com_my_app_MainActivity_openFile(JNIEnv * env, jobject this, jstring url)
{
......
...... //FFMPEG code

//---------------------------SDL part -------------------------//

window = SDL_CreateWindow("Window", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, 0, 0,
SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN);

if(window == NULL)
{
LOGE("Window not created: [%s]", SDL_GetError());
return;
}
LOGE("Window created");

renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
if(renderer == NULL)
{
LOGE("renderer not created: [%s]", SDL_GetError());
return;
}
LOGE("Rendering Created...");
}

这是我尝试过的另一个项目的代码(遵循 this 教程),我的 MainActivity 中没有我工作正常
   #include <stdlib.h>
#include <stdio.h>
#include <time.h>

#include "SDL.h"

typedef struct Sprite
{
SDL_Texture* texture;
Uint16 w;
Uint16 h;
} Sprite;

Sprite LoadSprite(const char* file, SDL_Renderer* renderer)
{
Sprite result;
result.texture = NULL;
result.w = 0;
result.h = 0;

SDL_Surface* temp;

/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL)
{
fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
return result;
}
result.w = temp->w;
result.h = temp->h;

/* Create texture from the image */
result.texture = SDL_CreateTextureFromSurface(renderer, temp);
if (!result.texture) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return result;
}
SDL_FreeSurface(temp);

return result;
}

void draw(SDL_Window* window, SDL_Renderer* renderer, const Sprite sprite)
{
int w, h;
SDL_GetWindowSize(window, &w, &h);
SDL_Rect destRect = {w/2 - sprite.w/2, h/2 - sprite.h/2, sprite.w, sprite.h};
/* Blit the sprite onto the screen */
SDL_RenderCopy(renderer, sprite.texture, NULL, &destRect);
}

int main(int argc, char *argv[])
{
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER))
{
fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
exit(1);
}

SDL_Window *window;
SDL_Renderer *renderer;

if(SDL_CreateWindowAndRenderer(0, 0, 0, &window, &renderer) < 0)
exit(2);

Sprite sprite = LoadSprite("image.bmp", renderer);
if(sprite.texture == NULL)
exit(2);

/* Main render loop */
Uint8 done = 0;
SDL_Event event;
while(!done)
{
/* Check for events */
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT || event.type == SDL_KEYDOWN )//|| event.type == SDL_FINGERDOWN)
{
done = 1;
}
}


/* Draw a gray background */
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);

draw(window, renderer, sprite);

/* Update the screen! */
SDL_RenderPresent(renderer);

SDL_Delay(10);
}

exit(0);

}

注意:我从这个正常工作的项目中创建了第一个项目(给出错误的项目)

我曾尝试使用#undef main 删除 SDL_main.h',但都不起作用。现在它开始给我一个错误说 'java.lang.UnsatisfiedLinkError: Cannot load library: soinfo_relocate(linker.cpp:975): cannot locate symbol "SDL_main" referenced by "libmain.so"...
我的安卓.mk
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeg
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libffmpeg.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
SDL_PATH := ../SDL
MY_FILES_PATH := ../src
LOCAL_MODULE := main
# Add your application source files here...
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
$(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/src/*.c))

LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -ljnigraphics -lGLESv1_CM -lGLESv2 -llog -lz -lm
LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
LOCAL_SHARED_LIBRARIES := SDL2
LOCAL_SHARED_LIBRARIES += ffmpeg
include $(BUILD_SHARED_LIBRARY)

最佳答案

无需包含 SDL_main.h,因为它包含在 SDL.h 中,我认为问题出在您的 main 函数中。

我试过你的代码,在 Visual Studio 中编译得很好。

创建一个新项目并按照以下步骤操作 http://www.willusher.io/sdl2%20tutorials/2013/08/15/lesson-0-setting-up-sdl/

关于android - 即使包含,也无法创建 SDL_Window 给出 SDL_Main.h 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27544597/

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