Shared Library symbols not listed - Linux

This is a discussion on Shared Library symbols not listed - Linux ; Hi, I have 3 cpp classes and i compiled it to form a .so file, unfortunately the methods inside these cpp files are not listed with "nm -C -D" option. I have given below the flags i have used while ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: Shared Library symbols not listed

  1. Shared Library symbols not listed

    Hi,

    I have 3 cpp classes and i compiled it to form a .so file,
    unfortunately the methods inside these cpp files are not listed with
    "nm -C -D" option.

    I have given below the flags i have used while compiling.

    Is there any possible solution for this

    Thanks in Advance!


    c++ -fno-rtti -fno-exceptions -Wall -Wconversion -Wpointer-arith -
    Wcast-align -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-
    non-virtual-dtor -Wno-long-long -pedantic -fshort-wchar -pthread -
    pipe -DNDEBUG -DTRIMMED -O -fPIC -shared -Wl,-z,defs -Wl,-
    h,libhello.so -o libhello.so libwq.o pij.o -Wl,--whole-
    archive ../todo.a -Wl,--no-whole-archive -rdynamic -lXi -lXext -
    lX11 -lm -lXt -ldl -lm


  2. Re: Shared Library symbols not listed

    On Oct 19, 1:30 pm, meen...@gmail.com wrote:
    > Hi,
    >
    > I have 3 cpp classes and i compiled it to form a .so file,
    > unfortunately the methods inside these cpp files are not listed with
    > "nm -C -D" option.
    >
    > I have given below the flags i have used while compiling.
    >
    > Is there any possible solution for this
    >
    > Thanks in Advance!
    >
    > c++ -fno-rtti -fno-exceptions -Wall -Wconversion -Wpointer-arith -
    > Wcast-align -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-
    > non-virtual-dtor -Wno-long-long -pedantic -fshort-wchar -pthread -
    > pipe -DNDEBUG -DTRIMMED -O -fPIC -shared -Wl,-z,defs -Wl,-
    > h,libhello.so -o libhello.so libwq.o pij.o -Wl,--whole-
    > archive ../todo.a -Wl,--no-whole-archive -rdynamic -lXi -lXext -
    > lX11 -lm -lXt -ldl -lm


    I faced a similar problem while working with C on Hp machine running
    linux and gcc 4.2
    let me suggest you the method i used to solve this, hope it may help
    you
    ->Please compile the individual module with -fpic option and
    create object files
    ->Then rebuild to make the shared library
    ->Still if the problem exist try to interchange the position
    of -fpic -shared to -fpic -shared
    i don't know exactly how gcc uses its argument

    Best Of luck
    Rakesh UV




  3. Re: Shared Library symbols not listed

    meendar@gmail.com writes:

    > I have 3 cpp classes and i compiled it to form a .so file,
    > unfortunately the methods inside these cpp files are not listed with
    > "nm -C -D" option.


    Don't ask in generalities; ask *specifics*.
    What is the name of the first class that is "missing"?

    What is the output from:

    nm -D libhello.so | grep NameOfClass
    nm libhello.so | grep NameOfClass
    nm libwq.o pij.o ../todo.a | grep NameOfClass

    Also show some code that is supposed to define the "missing" methods.

    > Is there any possible solution for this


    There most definitely is. Please also see:
    http://catb.org/esr/faqs/smart-questions.html

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  4. Re: Shared Library symbols not listed

    On Oct 20, 7:59 am, Paul Pluzhnikov
    wrote:
    > meen...@gmail.com writes:
    > > I have 3 cpp classes and i compiled it to form a .so file,
    > > unfortunately the methods inside these cpp files are not listed with
    > > "nm -C -D" option.

    >
    > Don't ask in generalities; ask *specifics*.
    > What is the name of the first class that is "missing"?
    >
    > What is the output from:
    >
    > nm -D libhello.so | grep NameOfClass
    > nm libhello.so | grep NameOfClass
    > nm libwq.o pij.o ../todo.a | grep NameOfClass
    >
    > Also show some code that is supposed to define the "missing" methods.
    >
    > > Is there any possible solution for this

    >
    > There most definitely is. Please also see:
    > http://catb.org/esr/faqs/smart-questions.html
    >
    > Cheers,
    > --
    > In order to understand recursion you must first understand recursion.
    > Remove /-nsp/ for email.


    Hi Paul,


    > Don't ask in generalities; ask *specifics*.
    > What is the name of the first class that is "missing"?


    certainly, i will do that in further questions.

    No class is listed under grep NameofClass for all the below statements
    However i managed to get grep NameOfMethod which is given below,

    > nm -D libhello.so | grep NameOfMethod

    -- Doesn't show anything

    > nm libhello.so | grep NameOfMethod


    ----Shows the method name with the address as
    000019dc t getNameQuery

    > nm libwq.o pij.o ../todo.a | grep NameOfMethod


    ----Shows the method name with the address as
    000001c8 t getNameQuery


    Thanks



  5. Re: Shared Library symbols not listed

    meendar@gmail.com writes:

    >> Don't ask in generalities; ask *specifics*.
    >> What is the name of the first class that is "missing"?

    ....
    >> Don't ask in generalities; ask *specifics*.
    >> What is the name of the first class that is "missing"?


    There is no need to quote the entire message, and then individual
    pieces of it again.

    >> nm -D libhello.so | grep NameOfMethod

    > -- Doesn't show anything
    >
    >> nm libhello.so | grep NameOfMethod

    >
    > ----Shows the method name with the address as
    > 000019dc t getNameQuery


    That function is *not* a class method; it's a "stand-alone" function
    with static "C" linkage. Since it is static, it is only accessible
    in the one object file in which it is defined, and nowhere else.

    As such, there is no need for the linker to export it in the dynamic
    table; in fact it would be *wrong* for the linker to export such
    function (that would make it accessible, and possibly in conflict
    with other definitions of that symbol).

    You didn't show any code :-(
    I am guessing you did something like this:

    // SomeClass.h
    class SomeClass { public: static char *getNameQuery(); /* ... rest ... */ };

    // SomeClass.cpp
    static char *getNameQuery() { /* implementation */ }

    but what you really meant to do was something entirely different:

    // SomeClass.cpp
    char *SomeClass::getNameQuery() { /* implementation */ }


    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  6. Re: Shared Library symbols not listed

    On Oct 22, 10:45 am, Paul Pluzhnikov
    wrote:
    > meen...@gmail.com writes:
    > >> Don't ask in generalities; ask *specifics*.
    > >> What is the name of the first class that is "missing"?

    > ...
    > >> Don't ask in generalities; ask *specifics*.
    > >> What is the name of the first class that is "missing"?

    >
    > There is no need to quote the entire message, and then individual
    > pieces of it again.
    >
    > >> nm -D libhello.so | grep NameOfMethod

    > > -- Doesn't show anything

    >
    > >> nm libhello.so | grep NameOfMethod

    >
    > > ----Shows the method name with the address as
    > > 000019dc t getNameQuery

    >
    > That function is *not* a class method; it's a "stand-alone" function
    > with static "C" linkage. Since it is static, it is only accessible
    > in the one object file in which it is defined, and nowhere else.
    >
    > As such, there is no need for the linker to export it in the dynamic
    > table; in fact it would be *wrong* for the linker to export such
    > function (that would make it accessible, and possibly in conflict
    > with other definitions of that symbol).
    >
    > You didn't show any code :-(
    > I am guessing you did something like this:
    >
    > // SomeClass.h
    > class SomeClass { public: static char *getNameQuery(); /* ... rest ... */ };
    >
    > // SomeClass.cpp
    > static char *getNameQuery() { /* implementation */ }
    >
    > but what you really meant to do was something entirely different:
    >
    > // SomeClass.cpp
    > char *SomeClass::getNameQuery() { /* implementation */ }
    >
    > Cheers,
    > --
    > In order to understand recursion you must first understand recursion.
    > Remove /-nsp/ for email.


    Here is the sample of code i am using,

    #include "plugin.h"
    #include "nsIServiceManager.h"
    #include "nsIMemory.h"
    #include "nsISupportsUtils.h" // this is where some useful macros
    defined

    // service manager which will give the access to all public browser
    services
    // we will use memory service as an illustration
    nsIServiceManager * gServiceManager = NULL;

    // Unix needs this
    #ifdef XP_UNIX
    #define MIME_TYPES_HANDLED "application/simple-plugin"
    #define PLUGIN_NAME "Simple Plugin Example for Mozilla"
    #define MIME_TYPES_DESCRIPTION MIME_TYPES_HANDLED"::"PLUGIN_NAME
    #define PLUGIN_DESCRIPTION PLUGIN_NAME " (Plug-ins SDK sample)"
    extern "C"
    {
    char* NPP_GetMIMEDescription(void)
    {
    fprintf(stdout,"Pramana -- Plugin.cpp -MEDescription");
    return(MIME_TYPES_DESCRIPTION);
    }
    }
    // get values per plugin
    NPError NS_PluginGetValue(NPPVariable aVariable, void *aValue)
    {
    NPError err = NPERR_NO_ERROR;
    switch (aVariable) {
    case NPPVpluginNameString:
    *((char **)aValue) = PLUGIN_NAME;
    break;
    case NPPVpluginDescriptionString:
    *((char **)aValue) = PLUGIN_DESCRIPTION;
    break;
    default:
    err = NPERR_INVALID_PARAM;
    break;
    }
    return err;
    }
    #endif //XP_UNIX

    //////////////////////////////////////
    //
    // general initialization and shutdown
    //
    NPError NS_PluginInitialize()
    {
    fprintf(stdout,"Pramana -- Plugin.cpp -NS_PluginInitialize");
    // this is probably a good place to get the service manager
    // note that Mozilla will add reference, so do not forget to release
    nsISupports * sm = NULL;

    NPN_GetValue(NULL, NPNVserviceManager, &sm);

    // Mozilla returns nsIServiceManager so we can use it directly;
    doing QI on
    // nsISupports here can still be more appropriate in case something
    is changed
    // in the future so we don't need to do casting of any sort.
    if(sm) {
    sm->QueryInterface(NS_GET_IID(nsIServiceManager),
    (void**)&gServiceManager);
    NS_RELEASE(sm);
    }

    return NPERR_NO_ERROR;
    }

    void NS_PluginShutdown()
    {
    fprintf(stdout,"Pramana -- Plugin.cpp -NS_PluginShutdown");
    // we should release the service manager
    NS_IF_RELEASE(gServiceManager);
    gServiceManager = NULL;
    }

    /////////////////////////////////////////////////////////////
    //
    // construction and destruction of our plugin instance object
    //
    nsPluginInstanceBase * NS_NewPluginInstance(nsPluginCreateData *
    aCreateDataStruct)
    {
    if(!aCreateDataStruct)
    return NULL;

    nsPluginInstance * plugin = new nsPluginInstance(aCreateDataStruct-
    >instance);

    return plugin;
    }

    void NS_DestroyPluginInstance(nsPluginInstanceBase * aPlugin)
    {
    if(aPlugin)
    delete (nsPluginInstance *)aPlugin;
    }

    ////////////////////////////////////////
    //
    // nsPluginInstance class implementation
    //
    nsPluginInstance::nsPluginInstance(NPP aInstance) :
    nsPluginInstanceBase(),
    mInstance(aInstance),
    mInitialized(FALSE),
    mScriptablePeer(NULL)
    {
    mString[0] = '\0';
    }

    nsPluginInstance::~nsPluginInstance()
    {
    // mScriptablePeer may be also held by the browser
    // so releasing it here does not guarantee that it is over
    // we should take precaution in case it will be called later
    // and zero its mPlugin member
    mScriptablePeer->SetInstance(NULL);
    NS_IF_RELEASE(mScriptablePeer);
    }

    NPBool nsPluginInstance::init(NPWindow* aWindow)
    {
    fprintf(stdout,"Pramana -- Plugin.cpp -NS_Plugininit");
    if(aWindow == NULL)
    return FALSE;

    mInitialized = TRUE;
    return TRUE;
    }

    void nsPluginInstance::shut()
    {
    mInitialized = FALSE;
    }

    NPBool nsPluginInstance::isInitialized()
    {
    fprintf(stdout,"Pramana -- Plugin.cpp -NS_Plugininit-is");
    return mInitialized;
    }

    void nsPluginInstance::getVersion(char* *aVersion)
    {
    fprintf(stdout,"Pramana -- Plugin.cpp -getVersion");
    const char *ua = NPN_UserAgent(mInstance);
    char*& version = *aVersion;

    // although we can use NPAPI NPN_MemAlloc call to allocate memory:
    // version = (char*)NPN_MemAlloc(strlen(ua) + 1);
    // for illustration purposed we use the service manager to access
    // the memory service provided by Mozilla
    nsIMemory * nsMemoryService = NULL;

    if (gServiceManager) {
    // get service using its contract id and use it to allocate the
    memory
    gServiceManager->GetServiceByContractID("@mozilla.org/xpcom/memory-
    service;1", NS_GET_IID(nsIMemory), (void **)&nsMemoryService);
    if(nsMemoryService)
    version = (char *)nsMemoryService->Alloc(strlen(ua) + 1);
    }

    if (version)
    strcpy(version, ua);

    // release service
    NS_IF_RELEASE(nsMemoryService);
    }

    // ==============================
    // ! Scriptability related code !
    // ==============================
    //
    // here the plugin is asked by Mozilla to tell if it is scriptable
    // we should return a valid interface id and a pointer to
    // nsScriptablePeer interface which we should have implemented
    // and which should be defined in the corressponding *.xpt file
    // in the bin/components folder
    NPError nsPluginInstance::GetValue(NPPVariable aVariable, void
    *aValue)
    {
    fprintf(stdout,"Pramana -- Plugin.cpp -getValue");
    NPError rv = NPERR_NO_ERROR;

    switch (aVariable) {
    case NPPVpluginScriptableInstance: {
    // addref happens in getter, so we don't addref here
    nsISimplePlugin * scriptablePeer = getScriptablePeer();
    if (scriptablePeer) {
    *(nsISupports **)aValue = scriptablePeer;
    } else
    rv = NPERR_OUT_OF_MEMORY_ERROR;
    }
    break;

    case NPPVpluginScriptableIID: {
    static nsIID scriptableIID = NS_ISIMPLEPLUGIN_IID;
    nsIID* ptr = (nsIID *)NPN_MemAlloc(sizeof(nsIID));
    if (ptr) {
    *ptr = scriptableIID;
    *(nsIID **)aValue = ptr;
    } else
    rv = NPERR_OUT_OF_MEMORY_ERROR;
    }
    break;

    default:
    break;
    }

    return rv;
    }

    // ==============================
    // ! Scriptability related code !
    // ==============================
    //
    // this method will return the scriptable object (and create it if
    necessary)
    nsScriptablePeer* nsPluginInstance::getScriptablePeer()
    {
    fprintf(stdout,"Pramana -- Plugin.cpp -getScriptablePeer");
    if (!mScriptablePeer) {
    mScriptablePeer = new nsScriptablePeer(this);
    if(!mScriptablePeer)
    return NULL;

    NS_ADDREF(mScriptablePeer);
    }

    // add reference for the caller requesting the object
    NS_ADDREF(mScriptablePeer);
    return mScriptablePeer;
    }

    I need to export all the methods dynamically while calling this
    libarary.
    After created the .so file , i have used dlopen to open this library ,
    and dlsym to get the pointer for NPP_GetMIMEDescription method in this
    library, however dlsym always return ' null ' instead of function
    pointer, with the exception 'undefined reference' to
    NPP_GetMIMEDescription.

    Thanks




  7. Re: Shared Library symbols not listed

    meendar@gmail.com writes:

    > Here is the sample of code i am using,

    ....
    > // Unix needs this
    > #ifdef XP_UNIX
    > #define MIME_TYPES_HANDLED "application/simple-plugin"
    > #define PLUGIN_NAME "Simple Plugin Example for Mozilla"
    > #define MIME_TYPES_DESCRIPTION MIME_TYPES_HANDLED"::"PLUGIN_NAME
    > #define PLUGIN_DESCRIPTION PLUGIN_NAME " (Plug-ins SDK sample)"
    > extern "C"
    > {
    > char* NPP_GetMIMEDescription(void)
    > {
    > fprintf(stdout,"Pramana -- Plugin.cpp -MEDescription");
    > return(MIME_TYPES_DESCRIPTION);
    > }
    > }

    ....
    > After created the .so file , i have used dlopen to open this library ,
    > and dlsym to get the pointer for NPP_GetMIMEDescription method in this
    > library, however dlsym always return ' null ' instead of function


    Above should have defined NPP_GetMIMEDescription function, *provided*
    the macro XP_UNIX is defined somewhere.

    You are still not asking "smart" questions, so it is still difficult
    to help you. A "smart" question would go something like this:

    I have the following code in my foobar.cpp file:
    ... sample code ...
    I compile that code with the following command line:
    ... compile command line ...
    ... version of g++ used ...
    I link that code into shared library as follows:
    ... link command line ...
    I expected NPP_GetMIMEDescription() to be defined and exported
    in the resulting shared library, but 'nm' tells me it wasn't
    ... command line you used to confirm that ...

    Why could that be?

    Here is how you can confirm that XP_UNIX is in fact *not* defined
    in your compilation (assuming your compile line was similar to your
    link line):

    c++ -fno-rtti -fno-exceptions -pedantic -fshort-wchar -pthread \
    -DNDEBUG -DTRIMMED -fPIC -dD -E foobar.cpp 2>/dev/null |
    grep XP_UNIX

    My guess is that you'll either not see XP_UNIX at all, or you'll
    see a '#define' follwed by '#undef' for it.

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

+ Reply to Thread