what will cause function exported as local function in .so?

Discussion in 'C++' started by DDD, May 18, 2010.

  1. DDD

    DDD Guest

    Hi,
    I have a C++ library in Linux. And I wanna export the function
    declared in .h file. But after compiled, the function is tagged by t,
    namely local symbol, and can not be used by another program.

    Any suggestions?

    Thanks in advance.
     
    DDD, May 18, 2010
    #1
    1. Advertising

  2. Try putting your code into a separate namespace.

    "DDD" <> wrote in message
    news:...
    > Hi,
    > I have a C++ library in Linux. And I wanna export the function
    > declared in .h file. But after compiled, the function is tagged by t,
    > namely local symbol, and can not be used by another program.
    >
    > Any suggestions?
    >
    > Thanks in advance.
     
    Sprechen sie von C++, May 18, 2010
    #2
    1. Advertising

  3. DDD

    DDD Guest

    I checked .a file, and the same function exported as T in .a.

    Sprechen sie von C++ wrote:
    > Try putting your code into a separate namespace.
    >
    > "DDD" <> wrote in message
    > news:...
    > > Hi,
    > > I have a C++ library in Linux. And I wanna export the function
    > > declared in .h file. But after compiled, the function is tagged by t,
    > > namely local symbol, and can not be used by another program.
    > >
    > > Any suggestions?
    > >
    > > Thanks in advance.
     
    DDD, May 18, 2010
    #3
  4. DDD

    mzdude Guest

    On May 18, 1:04 am, DDD <> wrote:
    > I checked .a file, and the same function exported as T in .a.
    >
    > Sprechen sie von C++ wrote:
    >
    >
    >
    > > Try putting your code into a separate namespace.

    >
    > > "DDD" <> wrote in message
    > >news:....
    > > > Hi,
    > > > I have a C++ library in Linux. And I wanna export the function
    > > > declared in .h file. But after compiled, the function is tagged by t,
    > > > namely local symbol, and can not be used by another program.

    >
    > > > Any suggestions?

    >
    > > > Thanks in advance.- Hide quoted text -

    >
    > - Show quoted text -


    You are most likely running into name mangling.

    Use extern "C" to prevent that.
     
    mzdude, May 18, 2010
    #4
  5. DDD

    DDD Guest

    mzdude wrote:
    > On May 18, 1:04 am, DDD <> wrote:
    > > I checked .a file, and the same function exported as T in .a.
    > >
    > > Sprechen sie von C++ wrote:
    > >
    > >
    > >
    > > > Try putting your code into a separate namespace.

    > >
    > > > "DDD" <> wrote in message
    > > >news:....
    > > > > Hi,
    > > > > I have a C++ library in Linux. And I wanna export the function
    > > > > declared in .h file. But after compiled, the function is tagged by t,
    > > > > namely local symbol, and can not be used by another program.

    > >
    > > > > Any suggestions?

    > >
    > > > > Thanks in advance.- Hide quoted text -

    > >
    > > - Show quoted text -

    >
    > You are most likely running into name mangling.
    >
    > Use extern "C" to prevent that.


    Using exterc "C" has no efficient.

    I check .o file of that export function.
    $>nm the.o
    ....
    000000e0 T Close
    ....

    $>nm libthe.a
    ....
    00000090 T Close

    but nm libthe.so
    oooooo80 t Close


    ....
     
    DDD, May 19, 2010
    #5
  6. DDD

    DDD Guest

    I find the solution now.

    Because -fvisibility=hidden option passed to g++.

    And my project is an ACE build application. I can type
    make no_hidden_visibility=1 to make the .so.

    Thanks.

    Reference:
    http://gcc.gnu.org/wiki/Visibility
    http://developer.apple.com/mac/libr.../CppRuntimeEnv/Articles/SymbolVisibility.html

    Yannick Tremblay wrote:
    > In article <..com>,
    > mzdude <> wrote:
    > >On May 18, 1:04�am, DDD <> wrote:
    > >> I checked .a file, and the same function exported as T in .a.
    > >>
    > >> Sprechen sie von C++ wrote:
    > >>
    > >>
    > >>
    > >> > Try putting your code into a separate namespace.
    > >>
    > >> > "DDD" <> wrote in message
    > >> >news:...
    > >> > > Hi,
    > >> > > I have a C++ library in Linux. And I wanna export the function
    > >> > > declared in .h file. But after compiled, the function is tagged by t,
    > >> > > namely local symbol, and can not be used by another program.
    > >>
    > >> > > Any suggestions?
    > >>
    > >> > > Thanks in advance.- Hide quoted text -
    > >>
    > >> - Show quoted text -

    > >
    > >You are most likely running into name mangling.
    > >
    > >Use extern "C" to prevent that.

    >
    > Absolutely unrelated.
    >
    > extern "C" does stop name mangling but it is only relevant if you try
    > to call a C++ function from C code from a different compilation unit
    > that is compiled in C. Much simpler just to compile eveything in C++,
    > get the benefit of the stricter compiler and not worry about extern
    > "C" unless you really need to.
    >
    > Technically, your question really apply to a Linux or a g++ specific
    > group. But I'll diverge from the rule a bit:
    >
    > In a very simple way you should have something like
    >
    > file1.h
    > file1.cpp
    > file2.h
    > file2.cpp
    >
    > mainfile.cpp
    >
    > Use "g++ -c" to produce file1.o from file1.cpp
    > Use "g++ -c" to produce file2.o from file2.cpp
    > Use "g++ -shared -fpic" to produce libfiles.so from file1.o and
    > file2.o
    >
    > You can use "nm" to list symbols in libfiles.so. Pipe the output of
    > nm into c++filt to see demangled names.
    >
    > Use "g++ -c" to produce mainfile.o from mainfile.cpp
    > Use "g++ -lfiles" produce mainfile from mainfile.o by linking it with
    > the shared object library libfiles.so
    >
    > You can also use "ar" to produce a static lib instead of a shared
    > object one.
    >
    > I think any additional details and clarification would be better asked
    > in a GNU g++ group or in a linux programming group.
     
    DDD, May 20, 2010
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob

    Xml exported text

    Bob, Mar 5, 2004, in forum: Perl
    Replies:
    0
    Views:
    419
  2. Replies:
    8
    Views:
    301
    Rolf Magnus
    Feb 22, 2006
  3. farseer
    Replies:
    9
    Views:
    384
    farseer
    Jun 3, 2006
  4. Sisyphus
    Replies:
    4
    Views:
    94
    Michele Dondi
    Jan 14, 2005
  5. Henry Law
    Replies:
    4
    Views:
    218
    Ben Morrow
    Jan 31, 2008
Loading...

Share This Page