枯枯山戮
枯枯山戮

Reputation: 21

Trouble with undefined reference to Callstack library

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()'

Upvotes: 2

Views: 1950

Answers (2)

oo153
oo153

Reputation: 41

In android 9.0, you should use libutilscallstack. Look "android/system/core/libutils/Android.bp" for more details.

Upvotes: 4

cmdLP
cmdLP

Reputation: 1856

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.

Upvotes: 0

Related Questions