Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8216347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:05:47+00:00 2026-06-07T12:05:47+00:00

I’m trying to write a program to call functions inside my .so library in

  • 0

I’m trying to write a program to call functions inside my .so library in Android.

main.cpp:

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

typedef int (*test_ptr)(int, int);

int main()
{
    int rc;
    void *handle;
    const char *error;

    handle = dlopen("./testdll.so", RTLD_LAZY);
    if(!handle){
        printf("dlopen %s\n", dlerror());
        return -1;
        }
    printf("dlopen success.\n");

    test_ptr test = (test_ptr)dlsym(handle, "max");
    error = dlerror();
    if (error)  {
        printf("error %s\n", error);
        dlclose(handle);
        return -1;
    }
    rc = test(10, 20);
    printf("rc = %d\n", rc);

    dlclose(handle);
    return 1;
}

testdll.cpp:

#include<stdio.h>

int max(int x,int y){
    return x>y?x:y;
}

Android.mk:

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
    testdll.cpp
LOCAL_MODULE_TAGS := optional
LOCAL_PRELINK_MODULE := true
LOCAL_LDFLAGS := -Wl,--export-dynamic
LOCAL_MODULE:= testdll
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
    main.cpp
LOCAL_LDLIBS := -ldl
LOCAL_SHARED_LIBRARIES := \
libcutils   \
libdl
LOCAL_MODULE_TAGS := optional
LOCAL_PRELINK_MODULE := true
LOCAL_MODULE := mytest
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
include $(BUILD_EXECUTABLE)

and I use mmm to make file and push testdll.so in to /system/lib and mytest to /data/data.

Then I run ./mytest, it can open testdll.so successed, but can’t connect my function.

error is:

Symbol not found:

Anybody know how to solve this problem?

==========================================================================================

Thanks everybody!

I call my functions successed use extern “C”.

But now, I change to use C++ to write the .so library and got the same error message.

testdll.cpp:

#include <sys/types.h>
#include <unistd.h>
#include <grp.h>

#include <binder/IPCThreadState.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include <utils/Log.h>

#include <private/android_filesystem_config.h>

#include <stdio.h>
#include "testdll.h"

using namespace android;
extern "C" {
    int TestClass::max(int x,int y){
        return x>y?x:y;
    }
}

testdll.h:

using namespace android;

class TestClass
{
    public:
        int max(int, int);
};

main.h:

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

typedef int (*test_ptr)(int, int);

int main()
{
    int rc;
    void *handle;
    const char *error;

    handle = dlopen("./testdll.so", RTLD_LAZY);
    if(!handle){
        printf("dlopen %s\n", dlerror());
        return -1;
    }
    printf("dlopen success.\n");

    test_ptr test = (test_ptr)dlsym(handle, "max");
    error = dlerror();
    if (error)  {
        printf("error %s\n", error);
        dlclose(handle);
        return -1;
    }
    rc = test(10, 20);
    printf("rc = %d\n", rc);

    dlclose(handle);
    return 1;
}

Then I got the same error message: Symbol not found:

I use objdump -TC to show:

DYNAMIC SYMBOL TABLE:
000003f5 g    DF .text  0000000a TestClass::max(int, int)
00000000      DF *UND*  00000000 __aeabi_unwind_cpp_pr0
00000000      DF *UND*  00000000 __cxa_finalize
000010f0 g    D  .bss   00000000 __dso_handle
00001000 g    D  .init_array    00000000 __INIT_ARRAY__
00001008 g    D  .fini_array    00000000 __FINI_ARRAY__
00000410 g    D  *ABS*  00000000 __exidx_end
00000400 g    D  *ABS*  00000000 __exidx_start
000010ec g    D  *ABS*  00000000 __data_start
000010ec g    D  *ABS*  00000000 _edata
000010ec g    D  *ABS*  00000000 __bss_start
000010ec g    D  *ABS*  00000000 __bss_start__
00001100 g    D  *ABS*  00000000 _bss_end__
00001100 g    D  *ABS*  00000000 __bss_end__
00001100 g    D  *ABS*  00000000 __end__
00001100 g    D  *ABS*  00000000 _end
00080000 g    D  *ABS*  00000000 _stack

How do I modify?

Thanks again!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:05:49+00:00Added an answer on June 7, 2026 at 12:05 pm

    TestClass::max(int, int) in your symbol table – does that mean you max function is a method of a class?

    Well, if so, you need to create a C wrap to your TestClass, for example

    extern "C"
    {
        int max (void *pHandle, int x, int y) 
        {
          TestClass *tcObject = (TestClass *)pHandle;
          return tcObject->max(x, y);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.