Shared Library and C++ Classes

R

Rainer Lehrig

An advantage of a shared library is,
that you don't need to relink your apps
if you do not change the interface of the library.

Question:
If you add a new method to a class,
will you have to relink the apps, that use the lib ?
 
G

Gianni Mariani

Rainer said:
An advantage of a shared library is,
that you don't need to relink your apps
if you do not change the interface of the library.

Question:
If you add a new method to a class,
will you have to relink the apps, that use the lib ?

That question is implementation dependant.

On most compilers I have used, if the method is not virtual, then you're
ok, if it's virtual you're probably out of luck.
 
S

Sam

Rainer said:
An advantage of a shared library is,
that you don't need to relink your apps
if you do not change the interface of the library.

Question:
If you add a new method to a class,
will you have to relink the apps, that use the lib ?

The correct answer depends on your specific compiler and operating system.
In general, adding a non-virtual, non-overloaded, method to a class does not
require a relink with most compilers and platforms.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBHsY0dx9p3GYHlUOIRAn1MAJ9Xh0Fdbatra/M782TfLR/qKNYblQCdGKJS
WWwEX1sVdRSJw1gc3sbwMv0=
=chGO
-----END PGP SIGNATURE-----
 
P

Pavel Shved

Question:
If you add a new method to a class,
will you have to relink the apps, that use the lib ?

Re-linking is not the most scary thing your program can face. You may
need to re-compile apps as well, especially if the method you add is
virtual.
 
R

Rainer Lehrig

It seems, it is better to recompile in order to be on the safe side.

The lib is portable, thus
..so/.dylib/.dll
are affected.
 
K

Keith Halligan

Rainer said:
An advantage of a shared library is,
that you don't need to relink your apps
if you do not change the interface of the library.

Question:
If you add a new method to a class,
will you have to relink the apps, that use the lib ?

As others have said once it's a non-virtual member then you should be
ok.

Some other things that will break binary compatibility of a shared lib
on most compilers are:
-> Reordering virtual members
-> Making a function virtual
-> Reordering base classes
-> Adding or removing a base class
-> Adding or removing a data members (if this class is exported)
-> Reordering data members.
 
V

Victor Bazarov

Keith said:
As others have said once it's a non-virtual member then you should be
ok.

Some other things that will break binary compatibility of a shared lib
on most compilers are:
-> Reordering virtual members
-> Making a function virtual
-> Reordering base classes
-> Adding or removing a base class
-> Adding or removing a data members (if this class is exported)

Adding or removing private static data members should be OK. Here's
a trick some may find useful. When adding a regular data member is
not possible, you can add a private class-wide storage of type
'std::map<yourclass*, wanteddatatype>', for example, and store the
emulated non-static "members" by keying them off 'this' pointers.
Ugly, but sometimes you have to do it.
-> Reordering data members.

V
 
J

James Kanze

An advantage of a shared library is,
that you don't need to relink your apps
if you do not change the interface of the library.
Question:
If you add a new method to a class,
will you have to relink the apps, that use the lib ?

You will have to recompile any source that includes the class
definition. And of course, if you recompile any source in the
application, you have to relink as well.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,965
Members
47,513
Latest member
JeremyLabo

Latest Threads

Top