ncnn使用GPU时报error: undefined reference to *******

导读

根据ncnn的官方教程使用vulkan-sdk编译了一个带gpu功能的libncnn.a库,官方教程如下:

https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-windows-x64-using-visual-studio-community-2017

详细错误

../../../../src/main/cppLibs/ncnn/lib/armeabi-v7a/libncnn.a(modelbin.cpp.o):modelbin.cpp:function ncnn::ModelBinFromDataReader::load(int, int) const: error: undefined reference to 'stderr'
../../../../src/main/cppLibs/ncnn/lib/armeabi-v7a/libncnn.a(modelbin.cpp.o):modelbin.cpp:function ncnn::ModelBinFromDataReader::load(int, int) const: error: undefined reference to 'stderr'
../../../../src/main/cppLibs/ncnn/lib/armeabi-v7a/libncnn.a(modelbin.cpp.o):modelbin.cpp:function ncnn::ModelBinFromDataReader::load(int, int) const: error: undefined reference to 'stderr'
../../../../src/main/cppLibs/ncnn/lib/armeabi-v7a/libncnn.a(modelbin.cpp.o):modelbin.cpp:function ncnn::ModelBinFromDataReader::load(int, int) const: error: undefined reference to 'stderr'
../../../../src/main/cppLibs/ncnn/lib/armeabi-v7a/libncnn.a(allocator.cpp.o):allocator.cpp:function ncnn::VkAllocator::flush(ncnn::VkBufferMemory*): error: undefined reference to 'vkFlushMappedMemoryRanges'
../../../../src/main/cppLibs/ncnn/lib/armeabi-v7a/libncnn.a(allocator.cpp.o):allocator.cpp:function ncnn::VkAllocator::invalidate(ncnn::VkBufferMemory*): error: undefined reference to 'vkInvalidateMappedMemoryRanges'
../../../../src/main/cppLibs/ncnn/lib/armeabi-v7a/libncnn.a(allocator.cpp.o):allocator.cpp:function ncnn::VkAllocator::create_buffer(unsigned int, unsigned int): error: undefined reference to 'vkCreateBuffer'
../../../../src/main/cppLibs/ncnn/lib/armeabi-v7a/libncnn.a(allocator.cpp.o):allocator.cpp:function ncnn::VkAllocator::allocate_memory(unsigned int): error: undefined reference to 'vkAllocateMemory'
../../../../src/main/cppLibs/ncnn/lib/armeabi-v7a/libncnn.a(allocator.cpp.o):allocator.cpp:function ncnn::VkAllocator::allocate_dedicated_memory(unsigned int, unsigned long long): error: undefined reference to 'vkAllocateMemory'
../../../../src/main/cppLibs/ncnn/lib/armeabi-v7a/libncnn.a(allocator.cpp.o):allocator.cpp:function ncnn::VkBlobBufferAllocator::clear(): error: undefined reference to 'vkDestroyBuffer'
../../../../src/main/cppLibs/ncnn/lib/armeabi-v7a/libncnn.a(allocator.cpp.o):allocator.cpp:function ncnn::VkBlobBufferAllocator::clear(): error: undefined reference to 'vkFreeMemory'
../../../../src/main/cppLibs/ncnn/lib/armeabi-v7a/libncnn.a(allocator.cpp.o):allocator.cpp:function ncnn::VkBlobBufferAllocator::clear(): error: undefined reference to 'vkUnmapMemory'
../../../../src/main/cppLibs/ncnn/lib/armeabi-v7a/libncnn.a(allocator.cpp.o):allocator.cpp:function ncnn::VkBlobBufferAllocator::fastMalloc(unsigned int): error: undefined reference to 'vkCreateBuffer'

解决办法

我在编译Android工程的时候,采用的是build.gradleCMakeLists.txt文件来进行配置的,如果你是使用的Android.mkapplication.mk文件可能配置上会有些区别

  • build.gradle文件中添加以下内容

想要使用GPU功能,Android的版本必须在24(Android7.0)以上

android {
    defaultConfig {
        minSdkVersion 24//应用支持Android的最低版本

        externalNativeBuild {
            cmake {
                arguments "-DANDROID_PLATFORM=android-24"//设置编译so文件的时候Android的版本
            }
        }
    }
}

  • CMakeLists.txt文件中添加如下内容
target_link_libraries( # Specifies the target library.
        jnigraphics
        vulkan)
  • Android.mk文件添加如下内容
LOCAL_LDLIBS := -lz -llog -ljnigraphics -lvulkan -landroid

application.mk中添加

APP_PLATFORM := android-24

 

你可能感兴趣的:(ncnn使用教程)