Narek
Narek

Reputation: 39881

nm utility to get what is defined in .so file returns error

I need to get the symbols defined in .so file. I use latest Mac OS and I do this:

 /usr/bin/nm  -gC libs/armeabi/libhello.so 

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm: invalid argument -C Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm [-agnopruUmxjlfAP[s segname sectname] [-] [-t format] [[-arch ] ...] [file ...]

As I understand this is another nm utility? It is connected with XCode? How to fix this issue?

EDIT: Adding code from which the .so file is created.

#include <android/log.h>
#include <stdio.h>
#include <jni.h>

       jint NativeAddition(JNIEnv *pEnv, jobject pObj, jint pa, jint pb)
       {
         return pa+pb;
       }

       jint NativeMultiplication(JNIEnv *pEnv, jobject pObj, jint pa,
       jint pb) {
         return pa*pb;
       }

       JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* pVm, void* reserved)
       {
           JNIEnv* env;
           if ((*pVm)->GetEnv(pVm, (void **)&env, JNI_VERSION_1_6)) {
return -1; }
           JNINativeMethod nm[2];
           nm[0].name = "NativeAddition";
           nm[0].signature = "(II)I";
           nm[0].fnPtr = NativeAddition;
           nm[1].name = "NativeMultiplication";
           nm[1].signature = "(II)I";
           nm[1].fnPtr = NativeMultiplication;
           jclass cls = (*env)->FindClass(env, "com/example/hellondk/HelloNDKActivity");
           // Register methods with env->RegisterNatives.
           (*env)->RegisterNatives(env, cls, nm, 2);
           return JNI_VERSION_1_6;
}

This example is from Android Native Development Kit Cookbook.

And also here is the usage message of my nm

Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm [-agnopruUmxjlfAP[s segname sectname] [-] [-t format] [[-arch ] ...] [file ...]

Upvotes: 0

Views: 837

Answers (2)

l&#39;L&#39;l
l&#39;L&#39;l

Reputation: 47264

In OS X the -C option for demangling symbols is absent.

# nm libs/armeabi/libhello.so | c++filt -p -i

You can instead use c++filt as a wrapper or invoke it as shown above.

Upvotes: 1

ichramm
ichramm

Reputation: 6642

Install macports and then, using macports run port install binutils.

Finally, run gobjdump -p app

Upvotes: 0

Related Questions