【发布时间】:2012-07-23 11:45:43
【问题描述】:
我在我的android项目中使用freeimage.so,我如何从C代码中引用这个库?或者是否需要访问这个库中的函数? 更多信息:我已将该功能放在项目的 armeabi 文件夹中 请向我提供您的宝贵建议 提前感谢您的宝贵努力
【问题讨论】:
-
还是不能放弃.so,和.a一起幸福生活吗? )
标签: android c++ c android-ndk shared-libraries
我在我的android项目中使用freeimage.so,我如何从C代码中引用这个库?或者是否需要访问这个库中的函数? 更多信息:我已将该功能放在项目的 armeabi 文件夹中 请向我提供您的宝贵建议 提前感谢您的宝贵努力
【问题讨论】:
标签: android c++ c android-ndk shared-libraries
.so 是动态库(也称为共享对象),而不是静态库。
要直接从 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
}
如果您需要静态的,请获取libfreeimage.a(或自己构建)并添加链接器指令-lfreeimage。
【讨论】: