Welcome, Guest. Please login or register.
Amiga Kit Amiga Store Iridium Banner AMIStore App Store A1200/A600 4xIDE Interface

AuthorTopic: C++ shared libs?  (Read 1798 times)

0 Members and 1 Guest are viewing this topic.

Offline andst

Re: C++ shared libs?
« Reply #15 on: December 06, 2012, 02:24:52 PM »
Quote from: Karlos;717689
I don't want to rain on anybody's parade, but if C++ classes are being exposed via AmigaOS shared libraries then I fully expect it to work for trivial concrete classes only. Either that, or you write your library functions based on some C structure that then becomes embedded as a delagate within a C++ class wrapper in which a bunch of inline method calls trampoline into your LVO.

I really can't see proper C++ shared code working that way. Not when you factor in things like inheritence, polymorphism and templating. Especially templating...


Ok, well it definitely needs to work for abstract classes as well if it's going to work with wxWidgets.  There's not too much multiple inheritance, but plenty of inheritance, polymorphism and templating obviously.  wxWidgets doesn't use all the more recent complex features of C++, but these basic building blocks are used quite frequently.

The SAS/C example is evidence that at least *some* incarnation of a C++ shared library is possible on Amiga.  SAS/C won't be able to compile wxWidgets, but I'm perfectly open to modifying gcc/g++ if needed.  I'm also thinking that C++ shared libraries works with DLL's on Windows.  Without knowing in detail exactly how it's done for DLL's, in my experience regular DLL's have mostly similar functionality to Amiga resident libraries.  Or is there any critical feature of DLL's that is missing from Amiga resident libraries?

Thanks all for responding.  Keep it going!
Amiga * wxWidgets * portingwx.blogspot.com
 

Offline psxphill

Re: C++ shared libs?
« Reply #16 on: December 06, 2012, 02:59:20 PM »
Quote from: andst;717776
The SAS/C example is evidence that at least *some* incarnation of a C++ shared library is possible on Amiga. SAS/C won't be able to compile wxWidgets, but I'm perfectly open to modifying gcc/g++ if needed. I'm also thinking that C++ shared libraries works with DLL's on Windows. Without knowing in detail exactly how it's done for DLL's, in my experience regular DLL's have mostly similar functionality to Amiga resident libraries. Or is there any critical feature of DLL's that is missing from Amiga resident libraries?

I'm not sure that you can derive from a C++ class in Windows DLL's either, that is what COM is for. COM standardises on what the vtable's look like and how to cast from one object type to another. I would guess that the AOS4 libraries are similar to COM.
 
There is no reason at all why it can't be done on AOS3, but you'll need to add compiler support & then you will be limited to that one compiler (but I guess you have that problem on AOS4 too). I don't know how SAS/C does it and whether it's worth copying their method or not.
 

Offline vidarh

Re: C++ shared libs?
« Reply #17 on: December 06, 2012, 04:28:31 PM »
Quote from: andst;717775
Vtables end up as regular symbols as far as I can tell.  Compiler dependent yes, but in theory should be fine.  Not sure if they could be shared between processes, but libs with some separate data per process is fully possible if I remember correctly.  I'm not sure I quite follow you w.r.t memory, do you mean correct C++ code might fail, or that broken user code would fail?


Broken user code would fail. The only issue there is that for every function wrapping a "new" operator there needs to be an equivalent one calling "delete" and users of the library needs to know they *must* use those to free the objects rather than, say, calling FreeMem().

But this is the same as in any C++. I mentioned it mainly in the context of the possible scenario with wrapping the C++ API in a C layer which could make it less obvious to a user. If you hand a user the actual C++ objects and have them use it from code compiled with the same compiler, then having to call delete presumably wouldn't surprise anyone.
 

Offline andst

Re: C++ shared libs?
« Reply #18 on: December 06, 2012, 07:12:49 PM »
Quote from: psxphill;717783
I'm not sure that you can derive from a C++ class in Windows DLL's either, that is what COM is for. COM standardises on what the vtable's look like and how to cast from one object type to another. I would guess that the AOS4 libraries are similar to COM.
 
There is no reason at all why it can't be done on AOS3, but you'll need to add compiler support & then you will be limited to that one compiler (but I guess you have that problem on AOS4 too). I don't know how SAS/C does it and whether it's worth copying their method or not.


Ok, well perhaps better to be limited to one compiler than no compiler at all.  But I guess it's also becoming clear to me that there is limited previous work in the area.  At least now I know a bit more about which areas need some thinking.
Amiga * wxWidgets * portingwx.blogspot.com
 

Offline andst

Re: C++ shared libs?
« Reply #19 on: December 06, 2012, 07:31:45 PM »
Quote from: vidarh;717795
Broken user code would fail. The only issue there is that for every function wrapping a "new" operator there needs to be an equivalent one calling "delete" and users of the library needs to know they *must* use those to free the objects rather than, say, calling FreeMem().

But this is the same as in any C++. I mentioned it mainly in the context of the possible scenario with wrapping the C++ API in a C layer which could make it less obvious to a user. If you hand a user the actual C++ objects and have them use it from code compiled with the same compiler, then having to call delete presumably wouldn't surprise anyone.


Okay.  There probably little need for FreeMem() in any wxWidgets user code, and in my experience it's even unusual to use the delete operator much, as object removal is pretty much always automatic.  It's different for library code obviously, but I guess there it's easier to influence code content  ;-)
Amiga * wxWidgets * portingwx.blogspot.com
 

Offline itix

Re: C++ shared libs?
« Reply #20 on: December 06, 2012, 08:39:31 PM »
Quote from: andst;717624
Hey,

As you may know I'm working on wxWidgets for Amiga.  It's a C++ lib and can get pretty big, so making it shared is clearly desirable.  OS 4 shared objects should be straightforward enough, but I'm wondering about normal resident libraries:


There are no shared objects in OS4. It is just using dynamic linking. Due to way Amiga operating systems work you cant have shared objects.

Quote
Has anyone done a resident C++ library before?


I have created libraries which are written in C++ but not libraries which expose C++ interface. It simply isnt possible because library system was not designed for that.

Quote
Are people using C++ on Amiga to any extent btw?  Or is it still mainly C and other languages?


It is mainly C and other languages.
My Amigas: A500, Mac Mini and PowerBook