Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用预先构建的静态库_Android_C++_C_Android Ndk_Shared Libraries - Fatal编程技术网

Android 使用预先构建的静态库

Android 使用预先构建的静态库,android,c++,c,android-ndk,shared-libraries,Android,C++,C,Android Ndk,Shared Libraries,我使用的是freeimage。所以对于我的android项目,我如何从C代码中引用这个库?或者访问这个库中的函数需要它吗? 进一步信息:我已经把该功能放在项目的armeabi文件夹中 请向我提供你的宝贵建议 提前感谢您的宝贵努力。动态库(也称为共享对象)也是如此,而不是静态库 要直接从C代码中使用.so文件,可以使用dlfcn POSIX API。这就像WinAPI中的LoadLibrary/GetProcAddress一样 #include <dlfcn.h> // sorry,

我使用的是freeimage。所以对于我的android项目,我如何从C代码中引用这个库?或者访问这个库中的函数需要它吗? 进一步信息:我已经把该功能放在项目的armeabi文件夹中 请向我提供你的宝贵建议 提前感谢您的宝贵努力。动态库(也称为共享对象)也是如此,而不是静态库

要直接从C代码中使用.so文件,可以使用dlfcn POSIX API。这就像WinAPI中的LoadLibrary/GetProcAddress一样

#include <dlfcn.h>

// sorry, I don't know the exact name of your FreeImage header file
#include "freeimage_header_file.h"

// declare the prototype
typedef FIBITMAP* ( DLL_CALLCONV* PFNFreeImage_LoadFromMemory )
         ( FREE_IMAGE_FORMAT, FIMEMORY*, int );

// declare the function pointer
PFNFreeImage_LoadFromMemory LoadFromMem_Function;

void some_function()
{
    void* handle = dlopen("freeimage.so", RTLD_NOW);

    LoadFromMem_Function = 
            ( PFNFreeImage_LoadFromMemory )dlsym(handle, "FreeImage_LoadFromMemory" );

    // use LoadFromMem_Function as you would use
    // statically linked FreeImage_LoadFromMemory
}
#包括
//抱歉,我不知道您的FreeImage头文件的确切名称
#包括“freeimage\u header\u file.h”
//声明原型
typedef FIBITMAP*(DLL_CALLCONV*PFNFreeImage_从内存加载)
(自由图像格式,FIMEMORY*,int);
//声明函数指针
PFNFreeImage_LoadFromMemory LoadFromMem_函数;
使某些函数无效()
{
void*handle=dlopen(“freeimage.so”,RTLD_NOW);
LoadFromMem_函数=
(PFNFreeImage_LoadFromMemory)dlsym(句柄,“FreeImage_LoadFromMemory”);
//使用LoadFromMem_函数,就像您将要使用的一样
//静态链接的FreeImage\u加载自内存
}

如果您需要一个静态的,请获取
libfreeimage.a
(或者自己构建一个),并添加链接器指令
-lfreeimage

仍然无法放弃。因此,与.a一起快乐地生活吧?)