Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Anything new on run-time libraries loading?

Reply
Thread Tools

Anything new on run-time libraries loading?

 
 
Dombo
Guest
Posts: n/a
 
      11-02-2011
Op 02-Nov-11 10:03, Edek schreef:
> On 11/02/2011 07:08 AM, Jorgen Grahn wrote:
>> On Tue, 2011-11-01, Dombo wrote:
>>> Op 01-Nov-11 6:28, Richard schreef:
>>>> [Please do not mail me a copy of your followup]
>>>>
>>>> Goran<(E-Mail Removed)> spake the secret code
>>>> <(E-Mail Removed)>
>>>> thusly:
>>>>
>>>>> [...] There's COM on Windows and that's about it.
>>>>
>>>> I believe the unix equivalent is CORBA.
>>>
>>> More like the cross-platform equivalent; CORBA implantations are
>>> available for other platforms as well (including Windows). There also
>>> many other middleware solutions.

>>
>> Although at that point, you might find yourself saying "maybe a plain
>> C interface to the loadable part isn't such a bad idea after all" ...

>
> Either I am missing something huge, or what are you talking about?
>
> You can have a C++ interface (see the FAQ in OP, the triangle class
> example)


CORBA is rather complex, you have to be a bit of masochist to enjoy
dealing with this stuff.

 
Reply With Quote
 
 
 
 
Jorgen Grahn
Guest
Posts: n/a
 
      11-03-2011
On Wed, 2011-11-02, Edek wrote:
> On 11/02/2011 07:08 AM, Jorgen Grahn wrote:
>> On Tue, 2011-11-01, Dombo wrote:
>>> Op 01-Nov-11 6:28, Richard schreef:
>>>> [Please do not mail me a copy of your followup]
>>>>
>>>> Goran<(E-Mail Removed)> spake the secret code
>>>> <(E-Mail Removed)> thusly:
>>>>
>>>>> [...] There's COM on Windows and that's about it.
>>>>
>>>> I believe the unix equivalent is CORBA.
>>>
>>> More like the cross-platform equivalent; CORBA implantations are
>>> available for other platforms as well (including Windows). There also
>>> many other middleware solutions.

>>
>> Although at that point, you might find yourself saying "maybe a plain
>> C interface to the loadable part isn't such a bad idea after all" ...

>
> Either I am missing something huge, or what are you talking about?


I'm saying that if your problem is the one in the original posting
(calling code in dlopen()ed libraries) you'd probably rather stick to
a C interface than go CORBA, or XMLsomething, or ...

(Perhaps the topic shifted without me noticing it, because I can't see
how CORBA solves that at all.)

> You can have a C++ interface (see the FAQ in OP, the triangle class
> example)


I missed that part -- but at a quick glance it doesn't seem much more
useful than a C interface.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
 
 
 
Edek
Guest
Posts: n/a
 
      11-03-2011
On 11/03/2011 07:26 PM, Jorgen Grahn wrote:
> On Wed, 2011-11-02, Edek wrote:
>> On 11/02/2011 07:08 AM, Jorgen Grahn wrote:
>>> On Tue, 2011-11-01, Dombo wrote:
>>>> Op 01-Nov-11 6:28, Richard schreef:
>>>>> [Please do not mail me a copy of your followup]
>>>>>
>>>>> Goran<(E-Mail Removed)> spake the secret code
>>>>> <(E-Mail Removed)> thusly:
>>>>>
>>>>>> [...] There's COM on Windows and that's about it.
>>>>>
>>>>> I believe the unix equivalent is CORBA.
>>>>
>>>> More like the cross-platform equivalent; CORBA implantations are
>>>> available for other platforms as well (including Windows). There also
>>>> many other middleware solutions.
>>>
>>> Although at that point, you might find yourself saying "maybe a plain
>>> C interface to the loadable part isn't such a bad idea after all" ...

>>
>> Either I am missing something huge, or what are you talking about?

>
> I'm saying that if your problem is the one in the original posting
> (calling code in dlopen()ed libraries) you'd probably rather stick to
> a C interface than go CORBA, or XMLsomething, or ...


I misaddressed my post, I think Goran started talking about
COM as if dlopen limited anybody to C:

> He who needs something more than that, C, should reach for
> some integration tech that defines needed binary-level compatibility.
> I find it amazing that virtually no such tech, that is cross-platform
> and in wide use, exist today. There's COM on Windows and that's about
> it.


So maybe LoadLibrary on Windows limits usage to C and one needs COM,
I don't know if that is true or not. Yeah, platforms do differ.

>
> (Perhaps the topic shifted without me noticing it, because I can't see
> how CORBA solves that at all.)


CORBA has a lot of features like load balancing, entities and so on;
using CORBA for a plugin framework is 'a bit of' an overkill. I see
no point in using CORBA on a single machine at all, I see the
major downside of using anything that is so heavy for simple
method calls, mainly because of PITA for developers.

>
>> You can have a C++ interface (see the FAQ in OP, the triangle class
>> example)

>
> I missed that part -- but at a quick glance it doesn't seem much more
> useful than a C interface.


If the library is C, I would use C. If it is C++, I would use C++,
not C. I find it useful to use C++ library by C++ API as opposite
to using a C++ lib by C API. BTW, plugins do know internals
of the main program with libraries and can freely use them.

One can just use C++, observing the same principles: ODR (put
each plugin in its own namespace) and other code correctness.

Technically build adjustments need to be made, see gcc faq on DSO.
In short for RTTI type information is by default pulled in on ELF
during linking, and loader does not see it, because linker does not
export it. So to get exceptions, templates and other such beasts
working, one needs to export all symbols (-E) and then the loader
can do its job during dlopen().

Edek


 
Reply With Quote
 
Edek
Guest
Posts: n/a
 
      11-03-2011
On 11/02/2011 11:03 PM, Paavo Helde wrote:
> Edek<(E-Mail Removed)> wrote in
> news:j8r0rb$mqa$(E-Mail Removed):
>> Why would you use nm? Why not make an extern C factory method
>> returning an object with virtual methods you can call (same example)?

>
> The OP did not like extern "C" for some reason. I just clarified it is
> technically possible to avoid it (though most probably not wise).


I guess it depends whether we mean "any library", or a plugin.

If the library is not a piece of unrelated software, one can write
a plugin without a single extern "C" and without dlsym. They
just need an API.

A working example (linux, gcc):

----------------------- api.h ------------------
#include <string>
#include <map>

using namespace std;

struct Exc {};

struct object
{
object () {};
virtual void hello () const =0;
virtual void throwExc () const = 0;
};

typedef map<string, object*> RegistryT;

-------------------- lib.cpp ------------------
#include "api.h"

#include <iostream>

using namespace std;

extern RegistryT registry;

namespace lib {

struct MyObject : public object
{
void hello () const { cerr << "MyObject" << endl; }
void throwExc () const { throw Exc() ; }
};

struct Registration
{
Registration () {
registry["lib"] = new MyObject();
}
};

static Registration reg;

} // namespace
--------------------- main.cpp ----------------
#include "api.h"

#include <dlfcn.h>
#include <iostream>

RegistryT registry;

int main()
{
dlopen("./lib.so", RTLD_NOW | RTLD_GLOBAL);

registry["lib"]->hello();

try {
registry["lib"]->throwExc();
} catch (Exc& e) {
cout << "caught Exc" << endl;
}

}

Edek

 
Reply With Quote
 
Waldek M.
Guest
Posts: n/a
 
      11-03-2011
On Wed, 02 Nov 2011 17:03:04 -0500, Paavo Helde wrote:
>> Why would you use nm? Why not make an extern C factory method
>> returning an object with virtual methods you can call (same example)?

>
> The OP did not like extern "C" for some reason. I just clarified it is
> technically possible to avoid it (though most probably not wise).


Actually, that wasn't exactly what I wrote even though it's close.
Yes, I do not like that in order to load C++ library from a C++
executable, I need to provide a C interface on one side and use it on the
other one.
Yet, I'm just asking if there is a better way with the - I definitely
wouldn't like to hack and depend on some particular version
of particular compiler...

Thanks anyway.

Waldek
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
standard libraries don't behave like standard 'libraries' Sriram Srinivasan Python 13 11-12-2009 06:05 PM
Using mandatory libraries (custom class loading vs. expanding libraries) Karsten Wutzke Java 21 06-29-2007 09:25 PM
Hello, anything new? B r ia n HTML 7 05-14-2004 07:31 PM
New Releases: Anything Else, Spy Kids 3D: Complete downloadable R1 DVD DB & info lists Doug MacLean DVD Video 0 10-16-2003 05:30 AM
Anything new better than Epson 2200 for quality, speed etc. Flierbk Digital Photography 10 09-20-2003 09:50 PM



Advertisments