473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

STL and shared libraries

Hi,

We have an application framework library that gets statically linked to any
applications we produce. (Windows apps, but I don't think that matters
here).

The framework is based heavily on the STL and the API uses many STL
constructs. Because of the static linking, and the fact that both app and
framework are built by the same compiler, we don't have any problems.

Now somebody has suggested we make the framework a shared library.

Of course, this probably means a big re-write is on the cards, and I am
aware that there can be issues if std::strings and other STL templated
classes are exposed on a shared library API.

Has anyone here had to tackle this problem? Any advice would be most
welcome. (Is there a common design pattern one could follow?)

I guess this is the reason why C++ libraries like QT and xerces provide
their OWN classes instead of using STL, right? :)

Thanks.

--
Regards,
Steve

"...which means he created the heaven and the earth... in the DARK! How good
is that?"

Nov 22 '05 #1
7 5173
On Sat, 12 Nov 2005 18:45:14 GMT, Steve <ro**@127.0.0.1> wrote:
Hi,

We have an application framework library that gets statically linked to any
applications we produce. (Windows apps, but I don't think that matters
here).

The framework is based heavily on the STL and the API uses many STL
constructs. Because of the static linking, and the fact that both app and
framework are built by the same compiler, we don't have any problems.

Now somebody has suggested we make the framework a shared library.

Of course, this probably means a big re-write is on the cards, and I am
aware that there can be issues if std::strings and other STL templated
classes are exposed on a shared library API.

Has anyone here had to tackle this problem? Any advice would be most
welcome. (Is there a common design pattern one could follow?)

I guess this is the reason why C++ libraries like QT and xerces provide
their OWN classes instead of using STL, right? :)

Thanks.


As long as you keep to the same environment (i.e. same compiler, etc.)
there's nothing inherent about the STL which would preclude making a
shared library with components which use it, as long as the clients
using the shared library are also compiled with the same compiler.

It all depends on how it is used, of course. You have to be
particularly careful with memory management issues when using shared
libraries, i.e. creating an object with "new" in one module and
destroying it with "delete" in a different module is definitely
something to avoid. The only way this can possibly work is if ALL
executables and libraries involved use the same C runtime library. And
the only way this would work is to link the CRT dynamically.

A good (and important) design pattern for this problem is the
"abstract factory". You would typically do the creation and
destruction of objects in the same factory class, exposing
Factory::Create() and Factory::Destroy() functions, instead of relying
on the clients to call new and delete.

--
Bob Hairgrove
No**********@Home.com
Nov 22 '05 #2
On 12/11/05 20:29, in article qa********************************@4ax.com,
"Bob Hairgrove" <in*****@bigfoot.com> wrote:

As long as you keep to the same environment (i.e. same compiler, etc.)
there's nothing inherent about the STL which would preclude making a
shared library with components which use it, as long as the clients
using the shared library are also compiled with the same compiler.
That¹s what I thought, but I have a wild aspiration to possibly license our
framework to existing clients. In that case, we can't really rely on them
using a specific compiler. (Perhaps it's far too wild!)
It all depends on how it is used, of course. You have to be
particularly careful with memory management issues when using shared
libraries, i.e. creating an object with "new" in one module and
destroying it with "delete" in a different module is definitely
something to avoid. The only way this can possibly work is if ALL
executables and libraries involved use the same C runtime library. And
the only way this would work is to link the CRT dynamically.
Absolutely. And I have been bitten with this before. Once bitten, and all
that!
A good (and important) design pattern for this problem is the
"abstract factory". You would typically do the creation and
destruction of objects in the same factory class, exposing
Factory::Create() and Factory::Destroy() functions, instead of relying
on the clients to call new and delete.


Nice idea. And by making making constructors private, I can ensure the user
will always need to call the Create and Destroy methods?
Thanks very much.

--
Regards,
Steve

"...which means he created the heaven and the earth... in the DARK! How good
is that?"

Nov 22 '05 #3
Ian
Steve wrote:
Hi,

We have an application framework library that gets statically linked to any
applications we produce. (Windows apps, but I don't think that matters
here).

The framework is based heavily on the STL and the API uses many STL
constructs. Because of the static linking, and the fact that both app and
framework are built by the same compiler, we don't have any problems.

Now somebody has suggested we make the framework a shared library.

Of course, this probably means a big re-write is on the cards, and I am
aware that there can be issues if std::strings and other STL templated
classes are exposed on a shared library API.
What C++ (rather than platform) issues do you foresee?
Has anyone here had to tackle this problem? Any advice would be most
welcome. (Is there a common design pattern one could follow?)
Many times and I've never had any issues.
I guess this is the reason why C++ libraries like QT and xerces provide
their OWN classes instead of using STL, right? :)

No, they just pre-date the standard library.

Ian
Nov 22 '05 #4
Steve wrote:
We have an application framework library that gets statically linked to any
applications we produce. (Windows apps, but I don't think that matters
here).

The framework is based heavily on the STL and the API uses many STL
constructs. Because of the static linking, and the fact that both app and
framework are built by the same compiler, we don't have any problems.

Now somebody has suggested we make the framework a shared library.

Of course, this probably means a big re-write is on the cards, and I am
aware that there can be issues if std::strings and other STL templated
classes are exposed on a shared library API.
The most simple approach is to link to the dynamic CRT library. This way you will only
have one heap, and this would save you from allocating in one heap (in main application)
and freeing in another heap (in your shared library), or vice verse.
Has anyone here had to tackle this problem? Any advice would be most
welcome. (Is there a common design pattern one could follow?) Another thing you must be aware of is the problem of "multiple singletons". If you have a
header file with something like
template<class T> struct A { static MySingleton singleton; };
MySingleton A::singleton;
and you include this header file both, in your shared library and in your main executable,
then you will get two instances of this singleton, one in the shared library, and another
one in the main executable. This wouldn't happen if you had a static library.
I guess this is the reason why C++ libraries like QT and xerces provide
their OWN classes instead of using STL, right? :)

No. They were written before the standard came out. Actually, afaik QT 4.0 uses STL.

--

Valentin Samko - http://www.valentinsamko.com
Nov 22 '05 #5
On 12/11/05 21:13, in article 11***************@drone2-svc-skyt.qsi.net.nz,
"Ian" <ia******@hotmail.com> wrote:
Steve wrote:
Hi,

We have an application framework library that gets statically linked to any
applications we produce. (Windows apps, but I don't think that matters
here).

The framework is based heavily on the STL and the API uses many STL
constructs. Because of the static linking, and the fact that both app and
framework are built by the same compiler, we don't have any problems.

Now somebody has suggested we make the framework a shared library.

Of course, this probably means a big re-write is on the cards, and I am
aware that there can be issues if std::strings and other STL templated
classes are exposed on a shared library API.
What C++ (rather than platform) issues do you foresee?


The implementation of std::string [as one example] might be, or, is probably
different between compilers - for example, GCC and Visual Studio.

Say the library was compiled with Visual Studio, then the API was used
within a gcc-compiled application, and the API had the following function:

void DoSomething( const std::string& );

GCC would pass a reference to it's own std::string object. The
implementation of the function (compiled under Visual Studio) is still
expecting a std::string, but its internals are likely to be completely
different.
Has anyone here had to tackle this problem? Any advice would be most
welcome. (Is there a common design pattern one could follow?)

Many times and I've never had any issues.


But are the libraries built with one compiler, then used in an application
built with a different one?

As I said in my reply to Bob Hairgrove, this may be just a wild aspiration I
have. I could probably live without this requirement for now!
I guess this is the reason why C++ libraries like QT and xerces provide
their OWN classes instead of using STL, right? :)

No, they just pre-date the standard library.


Are you sure? I can't confirm QT, but the initial beta release of xerces was
in November 1999.

--
Regards,
Steve

"...which means he created the heaven and the earth... in the DARK! How good
is that?"

Nov 22 '05 #6
Ian
Steve wrote:

What C++ (rather than platform) issues do you foresee?

The implementation of std::string [as one example] might be, or, is probably
different between compilers - for example, GCC and Visual Studio.

Say the library was compiled with Visual Studio, then the API was used
within a gcc-compiled application, and the API had the following function:

void DoSomething( const std::string& );

GCC would pass a reference to it's own std::string object. The
implementation of the function (compiled under Visual Studio) is still
expecting a std::string, but its internals are likely to be completely
different.

Ah, I missed you point. No, you cant mix C++ objects or libraries built
with different compilers. Unless you only interface through extern "C"
functions.


No, they just pre-date the standard library.

Are you sure? I can't confirm QT, but the initial beta release of xerces was
in November 1999.

Wasn't xerces an internal IBM project way before it was part of Apache?

Ian
Nov 22 '05 #7
Ian wrote:
GCC would pass a reference to it's own std::string object. The
implementation of the function (compiled under Visual Studio) is still
expecting a std::string, but its internals are likely to be completely
different.

Ah, I missed you point. No, you cant mix C++ objects or libraries built
with different compilers. Unless you only interface through extern "C"
functions.


Moreover, you can not mix objects built with the same compiler but when optimisation
settings differ in specific ways, and this is compiler dependent. The first problem would
be padding of class data members.

--

Valentin Samko - http://www.valentinsamko.com
Nov 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil | last post by:
I realize this is the php group, but I have a question that recurses back to my php install. My objective is a pure 64 bit shared object installation of php 5.0 on UltraSparc Solaris 9 compiled...
0
by: Frieder Loercher | last post by:
Hello, I am developping a (lammpi) parallel Application where any of the processes uses the Python script language. It works fine on Compaq Alpha and SUN Solaris5.9 On AIX5.1, it doesn't...
3
by: Rickard Lind | last post by:
Is there any way to build the python executable statically and still be able to load modules built as shared libraries? I'm trying to run python scripts on a stripped down FreeBSD (4.9) machine...
1
by: rinku24 | last post by:
We have two C++ libraries (Unix Shared objects) with the same class name and no namespace. Is there any way to load both the libraries and selectivly create the instance of the class from...
1
by: RHNewBie | last post by:
Hello, I have an executable which uses two shared libraries(A and Z). I do not have the source code for the executable. However I can tell the executable to load the shared libraries and invoke...
5
by: David T. Ashley | last post by:
I've occasionally had trouble compiling and linking programs that use shared libraries. That never made a lot of sense to me, because I thought the operating system went hunting for the symbols...
2
by: Tobias Bergmann | last post by:
Hi, I work on a big project that consists of many small linux C++ CGI binaries. This actually works fine but our problem is that we use many ..so libraries and we need to compile it separately...
3
by: Bala | last post by:
Hello, I am trying to create a shared library on solaris. The inputs to this library is a source file and then 2 static libraries. I need to call code within the shared library in another...
3
by: S S | last post by:
Hi Are there some known issues using STL with shared library. Recently I got some crash for which the reason I dont see any, and searching on goolge shown some such issues with shared library. ...
4
by: stuntgoat | last post by:
Hi, I want to start using Python 2.6 and 3000. I have several questions. What, in your experiences, is a functionally elegant solution to installing 2.6 and 3 from source without breaking...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.