小编Hra*_*yan的帖子

在Android平台上使用dlclose(...)时出现分段错误

(我使用动态加载API时存在一些问题<dlfcn.h>:dlopen(),dlclose()等),在Android上.我正在使用NDK独立工具链(版本8)来编译应用程序和库.Android版本是2.2.1 Froyo.

这是简单共享库的源代码.

#include <stdio.h>

int iii = 0;
int *ptr = NULL;

__attribute__((constructor))
static void init()
{
    iii = 653;
}

__attribute__((destructor))
static void cleanup()
{
}

int aaa(int i)
{
    printf("aaa %d\n", iii);
}
Run Code Online (Sandbox Code Playgroud)

这是使用上述库的程序源代码.

#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>

int main()
{
    void *handle;
    typedef int (*func)(int);
    func bbb;

    printf("start...\n");

    handle = dlopen("/data/testt/test.so", RTLD_LAZY);
    if (!handle)
    {
        return 0;
    }

    bbb = (func)dlsym(handle, "aaa");
    if (bbb == NULL)
    {
        return …
Run Code Online (Sandbox Code Playgroud)

c++ linux android android-ndk

11
推荐指数
2
解决办法
5797
查看次数

标签 统计

android ×1

android-ndk ×1

c++ ×1

linux ×1