I try to build a cpp file as below to an executable on the Android platform. Therefore, by calling dumping_callstack(), I can get call stack of my executable in run time. But there are some errors。

  1. cpp file:mycallstack.cpp

    #include <utils/CallStack.h>
    extern "C" void dumping_callstack()
    {
         CallStack stack("haha");
    }
    
  2. mycallstack.h

    void dumping_callstack();
    
  3. test.c

    #include <mycallstack.h>
    
    main()
    {
       dumping_callstack();
    } 
    
  4. android.mk

    LOCAL_SRC_FILES += mycallstack.cpp
    LOCAL_SHARED_LIBRARIES := libc libcutils liblog libutils
    

then compile.

error: undefined reference to 'android::CallStack::CallStack(char const*,int)'
error: undefined reference to 'android::CallStack::~CallStack()'

1 Answers

0
cmdLP On

The implementation of CallStack::CallStack and CallStack::~CallStack isn't provided to the compiler/linker. You might forgot to link it to the corresponding object file/library, I suggest you to read the documentation, there might be some information about linking. Sometimes it can help to just compile it with the -static switch, this makes the executable almost standalone, some libraries even require to be linked staticly.

It might also be the case, that the implementation is not available for release builds, I think the CallStack-class could only be available for debugging.