Re: Shared Objects Libraries and Symbols...
From: Lew Pitcher (Lew.Pitcher_at_td.com)
Date: 04/21/04
- Previous message: Kam: "Shared Objects Libraries and Symbols..."
- In reply to: Kam: "Shared Objects Libraries and Symbols..."
- Next in thread: Roger Leigh: "Re: Shared Objects Libraries and Symbols..."
- Reply: Roger Leigh: "Re: Shared Objects Libraries and Symbols..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 21 Apr 2004 11:47:56 -0400
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Kam wrote:
| Hi all,
|
| I have created some shared libraries for Linux.
| Well I'm not highly experienced with Unix/Linux libraries....
|
| Under Windows, I know we can specify which function or class to export or
| not.
| With my current shared libraries, all is exported by default.
| And any user could list the functions symbols using "nm" command line.
|
| My question is, is there a way under Linux/Unix to create a shared library
| and also
| specify which symbol to export or not ?
Of course it is.
Assuming you write your library in C, you use the C 'static' keyword on
all those functions that you do /not/ want to be public.
This is standard C, and has nothing directly to do with Linux. The
compiler by default (and by specification by the standards) exports all
functions not defined as 'static', and does not export the 'static'
functions. (See ISO C standard section 6.2.2, paragraph 3)
6.2.2 Linkages of identifiers
~ 1 An identifier declared in different scopes or in the same scope more
~ than once can be made to refer to the same object or function by a
~ process called linkage [21]. There are three kinds of linkage:
~ external, internal, and none.
~ 2 In the set of translation units and libraries that constitutes an
~ entire program, each declaration of a particular identifier with
~ external linkage denotes the same object or function. Within one
~ translation unit, each declaration of an identifier with internal
~ linkage denotes the same object or function. Each declaration of
~ an identifier with no linkage denotes a unique entity.
~ 3 If the declaration of a file scope identifier for an object or a
~ function contains the storageclass specifier static, the identifier
~ has internal linkage [22].
~ 4 For an identifier declared with the storage-class specifier extern
~ in a scope in which a prior declaration of that identifier is
~ visible [23] if the prior declaration specifies internal or
~ external linkage, the linkage of the identifier at the later
~ declaration is the same as the linkage specified at the prior
~ declaration. If no prior declaration is visible, or if the prior
~ declaration specifies no linkage, then the identifier has external
~ linkage.
~ 5 If the declaration of an identifier for a function has no
~ storage-class specifier, its linkage is determined exactly as if it
~ were declared with the storage-class specifier extern. If
~ the declaration of an identifier for an object has file scope and no
~ storage-class specifier, its linkage is external.
~ 6 The following identifiers have no linkage: an identifier declared to
~ be anything other than an object or a function; an identifier
~ declared to be a function parameter; a block scope identifier for an
~ object declared without the storage-class specifier extern.
~ 7 If, within a translation unit, the same identifier appears with both
~ internal and external linkage, the behavior is undefined.
~ [21] There is no linkage between different identifiers.
~ [22] A function declaration can contain the storage-class specifier
~ static only if it is at file scope; see 6.7.1.
~ [23] As specified in 6.2.1, the later declaration might hide the prior
~ declaration.
I'm sure that C++ and the other compiled languages have similar
capabilities.
| If it's possible, I guess the others non-exported symbols won't be visible
| with "nm" command ?
True enough.
- --
Lew Pitcher, IT Consultant, Enterprise Application Architecture
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
iD8DBQFAhpeqagVFX4UWr64RAoJzAJ9rIHoYLmgYScpMowqP+ZxyeN1YvQCeNTi8
a1VbP7cvL7x599W9O7S419A=
=1DRW
-----END PGP SIGNATURE-----
- Previous message: Kam: "Shared Objects Libraries and Symbols..."
- In reply to: Kam: "Shared Objects Libraries and Symbols..."
- Next in thread: Roger Leigh: "Re: Shared Objects Libraries and Symbols..."
- Reply: Roger Leigh: "Re: Shared Objects Libraries and Symbols..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|