public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* How to assign which symbols/functions to export from a .so file
@ 2007-12-13  9:22 "Chen(陈) Jun(军)"
  2007-12-13  9:35 ` 龙海涛
  2007-12-13  9:39 ` Brian Dessent
  0 siblings, 2 replies; 4+ messages in thread
From: "Chen(陈) Jun(军)" @ 2007-12-13  9:22 UTC (permalink / raw)
  To: gcc-help

Hello, everyone,

I'd like to know, when I generate a .so file with ``gcc -shared'', how 
can I assign which functions to export(visible by the  .so user).  This 
is important , because a .so author would probably like to hide his 
private functions so that the private symbols will not conflict with 
that of .so from other programmers.

Microsoft compiler use a .def to describe what symbols to export from a 
DLL, or, __declspec(dllexport) can easily export functions of a whole 
C++ class. Does the gcc world support this feature.

I search google with "gcc shared object export function", but no luck.

Looking forward to your kind answers.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to assign which symbols/functions to export from a .so file
  2007-12-13  9:22 How to assign which symbols/functions to export from a .so file "Chen(陈) Jun(军)"
@ 2007-12-13  9:35 ` 龙海涛
  2007-12-13  9:39 ` Brian Dessent
  1 sibling, 0 replies; 4+ messages in thread
From: 龙海涛 @ 2007-12-13  9:35 UTC (permalink / raw)
  To: "Chen(陈) Jun(军)"; +Cc: gcc-help

Chen(陈) Jun(军) 写道:
> Hello, everyone,
> 
> I'd like to know, when I generate a .so file with ``gcc -shared'', how 
> can I assign which functions to export(visible by the  .so user).  This 
> is important , because a .so author would probably like to hide his 
> private functions so that the private symbols will not conflict with 
> that of .so from other programmers.
> 
> Microsoft compiler use a .def to describe what symbols to export from a 
> DLL, or, __declspec(dllexport) can easily export functions of a whole 
> C++ class. Does the gcc world support this feature.

maybe option '-fvisibility' can answer you question.
you can search the gcc manual for more information.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to assign which symbols/functions to export from a .so file
  2007-12-13  9:22 How to assign which symbols/functions to export from a .so file "Chen(陈) Jun(军)"
  2007-12-13  9:35 ` 龙海涛
@ 2007-12-13  9:39 ` Brian Dessent
  2007-12-14 13:23   ` "Chen(陈) Jun(军)"
  1 sibling, 1 reply; 4+ messages in thread
From: Brian Dessent @ 2007-12-13  9:39 UTC (permalink / raw)
  To: Chen(?) Jun(?); +Cc: gcc-help

"Chen(?) Jun(?)" wrote:

> I'd like to know, when I generate a .so file with ``gcc -shared'', how
> can I assign which functions to export(visible by the  .so user).  This
> is important , because a .so author would probably like to hide his
> private functions so that the private symbols will not conflict with
> that of .so from other programmers.
> 
> Microsoft compiler use a .def to describe what symbols to export from a
> DLL, or, __declspec(dllexport) can easily export functions of a whole
> C++ class. Does the gcc world support this feature.

What platform are you talking about?  gcc uses whatever the underlying
platform supports, but that can vary considerably.  You have to remember
that gcc targets dozens and dozens of various combinations of operating
systems and architectures so don't assume that gcc=linux.

On PE platforms, gcc works similarly to the MS toolchain: __declspec
and/or a .def file, but also with the choice of using the auto-export
feature of the GNU linker if neither of the former are used.

On ELF platforms you use symbol visibility, either with
__attribute__((visibility)) or -fvisibility.  Read the fine manual: 

<http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#index-g_t_0040code_007bvisibility_007d-attribute-2100>
<http://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fvisibility-1837>

Brian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to assign which symbols/functions to export from a .so file
  2007-12-13  9:39 ` Brian Dessent
@ 2007-12-14 13:23   ` "Chen(陈) Jun(军)"
  0 siblings, 0 replies; 4+ messages in thread
From: "Chen(陈) Jun(军)" @ 2007-12-14 13:23 UTC (permalink / raw)
  To: gcc-help

Thank you very much for your answer. I just want to do that in Linux 
building Linux DSO, and your answer is just right for me. I tried it on 
gcc 4.1.0(SuSE Linux 10.1) and it does just what I've expected.

By the way, it is better for gcc manual to tell since what gcc version a 
specific compiler option is introduced, so that a gcc user don't have to 
hunt around the change-log to know that. Don't you think so?

Brian Dessent 写道:
> "Chen(?) Jun(?)" wrote:
>
>   
>> I'd like to know, when I generate a .so file with ``gcc -shared'', how
>> can I assign which functions to export(visible by the  .so user).  This
>> is important , because a .so author would probably like to hide his
>> private functions so that the private symbols will not conflict with
>> that of .so from other programmers.
>>
>> Microsoft compiler use a .def to describe what symbols to export from a
>> DLL, or, __declspec(dllexport) can easily export functions of a whole
>> C++ class. Does the gcc world support this feature.
>>     
>
> What platform are you talking about?  gcc uses whatever the underlying
> platform supports, but that can vary considerably.  You have to remember
> that gcc targets dozens and dozens of various combinations of operating
> systems and architectures so don't assume that gcc=linux.
>
> On PE platforms, gcc works similarly to the MS toolchain: __declspec
> and/or a .def file, but also with the choice of using the auto-export
> feature of the GNU linker if neither of the former are used.
>
> On ELF platforms you use symbol visibility, either with
> __attribute__((visibility)) or -fvisibility.  Read the fine manual: 
>
> <http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#index-g_t_0040code_007bvisibility_007d-attribute-2100>
> <http://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fvisibility-1837>
>
> Brian
>
>   

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-12-14 13:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-13  9:22 How to assign which symbols/functions to export from a .so file "Chen(陈) Jun(军)"
2007-12-13  9:35 ` 龙海涛
2007-12-13  9:39 ` Brian Dessent
2007-12-14 13:23   ` "Chen(陈) Jun(军)"

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).