有人可以协助解决此 NDK 链接器错误吗?已经工作了几个小时。 NDK错误?

Could someone please assist with this NDK linker error? Been working at it for hours. NDK bug?

我整天都在尝试编译 link 一个足够简单的程序(基本上是一个 hello world 示例)。我问过库的作者,他告诉我修复我的 linker 依赖项。相关信息如下:

我也试过用作者的构建工具编译并link将它作为静态库,但没有用。我还尝试了 STL 构建环境的所有变体。我做错了什么,还是其他问题?

testbgfx.cpp

#include <SDL.h>
#include <bgfxplatform.h>

#include <bgfx.h>

int main(int argc, char* args[])
{
// SDL_Init( SDL_INIT_EVERYTHING ); Uncommenting this did nothing
SDL_Rect bounds;
SDL_GetDisplayBounds(0,&bounds);
int height = bounds.h;
int width = bounds.w;
SDL_Window* window = SDL_CreateWindow("TestApp",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,width,height,SDL_WINDOW_MAXIMIZED);

bgfx_sdlSetWindow(window);


bgfx::init();

return 0;

}

Android.mk(客户端应用)

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := main

LOCAL_SRC_FILES := testbgfx.cpp
# Switching to static lib did nothing
#LOCAL_STATIC_LIBRARIES := bgfx
LOCAL_SHARED_LIBRARIES := SDL2 bx bgfx  

# Required for compilation
LOCAL_CXXFLAGS := $(LOCAL_CFLAGS) -D__STDC_LIMIT_MACRO -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS

LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog -lc -ldl -lm -landroid -lEGL

include $(BUILD_SHARED_LIBRARY)

$(call import-module,bx)
$(call import-module,bgfx)
$(call import-module,SDL2)

bgfx 库的 Android.mk(在 ndk 源目录中,根据需要)

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := bgfx
#This did nothing
#LOCAL_C_INCLUDES += src

#Disabled those to see that would happen - nothing
#LOCAL_CFLAGS := -Wall -Wextra -g -Wa,--noexecstack -no-canonical-prefixes -ffunction-sections -Wno-psabi -Wunused-value -Wundef -fstack-protector
#LOCAL_CXXFLAGS := $(LOCAL_CFLAGS) -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS -MMD -MP -fPIC -std=c++0x

LOCAL_SRC_FILES := src
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
#Enabling the following changed nothing
#LOCAL_C_INCLUDES := $(LOCAL_PATH)/3rdparty
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include

# This doesn't work
#LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/src/*.h
# Neither does this
#LOCAL_EXPORT_C_INCLUDES += $(wildcard $(LOCAL_PATH)/src/*h)


LOCAL_SHARED_LIBRARIES := bx
LOCAL_EXPORT_SHARED_LIBRARIES := bx

#Switching to static did nothing
#include $(BUILD_STATIC_LIBRARY)
include $(BUILD_SHARED_LIBRARY)

$(call import-modules,bx)

Android.mk for bx(实用程序库取决于我的 bgfx,也在 ndk 源目录中)

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := bx 
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(BUILD_SHARED_LIBRARY)

相关错误日志如下:

/home/noob/android/android-ndk-r10d/toolchains/arm-linux-androideabi- 4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -Wl,-soname,libmain.so -shared --sysroot=/home/noob/android/android-ndk-r10d/platforms/android-18/arch-arm ./obj/local/armeabi-v7a/objs/main/testbgfx.o ./obj/local/armeabi-v7a/libSDL2.a -lgcc ./obj/local/armeabi-v7a/libbx.so ./obj/local/armeabi-v7a/libbgfx.so ./obj/local/armeabi-v7a/libgnustl_shared.so -no-canonical-prefixes -march=armv7-a -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -mthumb -L/home/noob/android/android-ndk-r10d/platforms/android-18/arch-arm/usr/lib -lGLESv1_CM -lGLESv2 -llog -lc -ldl -lm -landroid -lEGL -Wl,--undefined=Java_org_libsdl_app_SDLActivity_nativeInit -ldl -lGLESv1_CM -lGLESv2 -llog -landroid /home/noob/android/android-ndk/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/libsupc++.a -lc -lm -o ./obj/local/armeabi-v7a/libmain.so jni/src/testbgfx.cpp:18: error: undefined reference to 'bgfx::init(bgfx::RendererType::Enum, bgfx::CallbackI*, bx::ReallocatorI*)' collect2: error: ld returned 1 exit status make: *** [obj/local/armeabi-v7a/libmain.so] Error 1

bgfx 的 Android.mk 实际上似乎没有列出任何要编译的源文件 - 您只列出了 LOCAL_SRC_FILES := src,这似乎是一个目录。您需要在此处列出所有单独的 C/C++ 源文件。