relocation error: plugin.so: undefined symbol: hello - Linux

This is a discussion on relocation error: plugin.so: undefined symbol: hello - Linux ; While building my application i run into the following problem. I Build a 'regular' executable (main). This executable explicitly loads a shared library (plugin.so) using dlopen. In this shared library a call is done on a global function (hello), this ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: relocation error: plugin.so: undefined symbol: hello

  1. relocation error: plugin.so: undefined symbol: hello

    While building my application i run into the following problem. I
    Build a 'regular' executable (main). This executable explicitly loads
    a shared library (plugin.so) using dlopen. In this shared library a
    call is done on a global function (hello), this global function
    (hello) is defined in main.

    Is this call from the shared library possible?

    When i call the function hello from the shared library i get a
    relocation error undefined symbol. Is this because the symbol is
    defined in the main executable and isn't available for the shared
    object file? Or is there something else which i'm doing wrong?

    Extra info:
    Error: relocation error: plugin.so: undefined symbol: hello

    readelf -s main gives. (Not a name mangling problem in my opinion):
    Num: Value Size Type Bind Vis Ndx Name
    4457: 00050280 176 FUNC GLOBAL DEFAULT 13 Hello


  2. Re: relocation error: plugin.so: undefined symbol: hello

    bjornms@gmail.com wrote:
    > plugin.so: undefined symbol: hello

    ^^^

    > Num: Value Size Type Bind Vis Ndx Name
    > 4457: 00050280 176 FUNC GLOBAL DEFAULT 13 Hello

    ^^^

    H vs h?

    Uli


  3. Re: relocation error: plugin.so: undefined symbol: hello

    bjornms@gmail.com writes:

    > While building my application i run into the following problem. I
    > Build a 'regular' executable (main). This executable explicitly loads
    > a shared library (plugin.so) using dlopen. In this shared library a
    > call is done on a global function (hello), this global function
    > (hello) is defined in main.
    >
    > Is this call from the shared library possible?


    Yes, but you have to link your main executable with '-rdynamic',
    because symbols in the main exe, which aren't referenced from
    outside at static link time, are not normally exported.

    > When i call the function hello from the shared library i get a
    > relocation error undefined symbol. Is this because the symbol is
    > defined in the main executable and isn't available for the shared
    > object file?


    Correct. To see what is "exported", do this:

    nm -D main | egrep ' [TDW] '

    > readelf -s main gives. (Not a name mangling problem in my opinion):
    > Num: Value Size Type Bind Vis Ndx Name
    > 4457: 00050280 176 FUNC GLOBAL DEFAULT 13 Hello


    As Ulrich Eckhardt noted, you may also have 'Hello' vs. 'hello'
    difference -- these are completely distinct.

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

  4. Re: relocation error: plugin.so: undefined symbol: hello

    bjornms@gmail.com writes:

    > While building my application i run into the following problem. I
    > Build a 'regular' executable (main). This executable explicitly loads
    > a shared library (plugin.so) using dlopen. In this shared library a
    > call is done on a global function (hello), this global function
    > (hello) is defined in main.
    >
    > Is this call from the shared library possible?
    >
    > When i call the function hello from the shared library i get a
    > relocation error undefined symbol. Is this because the symbol is
    > defined in the main executable and isn't available for the shared
    > object file? Or is there something else which i'm doing wrong?
    >
    > Extra info:
    > Error: relocation error: plugin.so: undefined symbol: hello
    >
    > readelf -s main gives. (Not a name mangling problem in my opinion):
    > Num: Value Size Type Bind Vis Ndx Name
    > 4457: 00050280 176 FUNC GLOBAL DEFAULT 13 Hello


    As someone else pointed out, there seems to be a h/H mismatch.

    Also, make sure you link your main executable with the -rdynamic flag
    to gcc.

    --
    Måns Rullgård
    mans@mansr.com

  5. Re: relocation error: plugin.so: undefined symbol: hello

    Because i couldn't copy paste it, it is a typo. But it should have
    been both Hello. But tommorow i will try the -rdynamic option.

    On 3 okt, 20:18, Måns Rullgård wrote:
    > bjor...@gmail.com writes:
    > > While building my application i run into the following problem. I
    > > Build a 'regular' executable (main). This executable explicitly loads
    > > a shared library (plugin.so) using dlopen. In this shared library a
    > > call is done on a global function (hello), this global function
    > > (hello) is defined in main.

    >
    > > Is this call from the shared library possible?

    >
    > > When i call the function hello from the shared library i get a
    > > relocation error undefined symbol. Is this because the symbol is
    > > defined in the main executable and isn't available for the shared
    > > object file? Or is there something else which i'm doing wrong?

    >
    > > Extra info:
    > > Error: relocation error: plugin.so: undefined symbol: hello

    >
    > > readelf -s main gives. (Not a name mangling problem in my opinion):
    > > Num: Value Size Type Bind Vis Ndx Name
    > > 4457: 00050280 176 FUNC GLOBAL DEFAULT 13 Hello

    >
    > As someone else pointed out, there seems to be a h/H mismatch.
    >
    > Also, make sure you link your main executable with the -rdynamic flag
    > to gcc.
    >
    > --
    > Måns Rullgård
    > m...@mansr.com




  6. Re: relocation error: plugin.so: undefined symbol: hello

    On Oct 3, 4:04 pm, Paul Pluzhnikov
    wrote:
    > bjor...@gmail.com writes:
    > > While building my application i run into the following problem. I
    > > Build a 'regular' executable (main). This executable explicitly loads
    > > a shared library (plugin.so) using dlopen. In this shared library a
    > > call is done on a global function (hello), this global function
    > > (hello) is defined in main.

    >
    > > Is this call from the shared library possible?

    >
    > Yes, but you have to link your main executable with '-rdynamic',
    > because symbols in the main exe, which aren't referenced from
    > outside at static link time, are not normally exported.
    >
    > > When i call the function hello from the shared library i get a
    > > relocation error undefined symbol. Is this because the symbol is
    > > defined in the main executable and isn't available for the shared
    > > object file?

    >
    > Correct. To see what is "exported", do this:
    >
    > nm -D main | egrep ' [TDW] '
    >
    > > readelf -s main gives. (Not a name mangling problem in my opinion):
    > > Num: Value Size Type Bind Vis Ndx Name
    > > 4457: 00050280 176 FUNC GLOBAL DEFAULT 13 Hello

    >
    > As Ulrich Eckhardt noted, you may also have 'Hello' vs. 'hello'
    > difference -- these are completely distinct.
    >
    > Cheers,
    > --
    > In order to understand recursion you must first understand recursion.
    > Remove /-nsp/ for email.


    The nm -D main | egrep '[TDW]' gives me:
    0050280 T Hello

    The -rdynamic option does not change this. Is there something else i
    might do wrong?


  7. Re: relocation error: plugin.so: undefined symbol: hello

    bjornms@gmail.com writes:

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


    [Please trim your replies.]

    > The nm -D main | egrep '[TDW]' gives me:
    > 0050280 T Hello


    That means 'Hello' *is* exported.
    [It also means that you are not very good at following directions,
    since this isn't the command I asked you to run ;-[

    > The -rdynamic option does not change this. Is there something else i
    > might do wrong?


    What is the *exact* error message?
    In your original message you said:

    relocation error: plugin.so: undefined symbol: hello

    If this was cut/paste, then you really need 'hello' to be exported,
    not 'Hello'.

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

+ Reply to Thread