From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4cabfb8e49247533 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!newsread.com!news-xfer.newsread.com!nntp.abs.net!news.abs.net!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Multiple shared libraries with a single spec References: <1131107328.981560.222350@g43g2000cwa.googlegroups.com> From: Stephen Leake Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (windows-nt) Cancel-Lock: sha1:sbA2KWl2iVQMdp5jJJ8ucLLhuYg= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 04 Nov 2005 09:09:55 -0500 NNTP-Posting-Host: 66.159.65.1 X-Complaints-To: abuse@toad.net X-Trace: news.abs.net 1131113407 66.159.65.1 (Fri, 04 Nov 2005 09:10:07 EST) NNTP-Posting-Date: Fri, 04 Nov 2005 09:10:07 EST Xref: g2news1.google.com comp.lang.ada:6188 Date: 2005-11-04T09:09:55-05:00 List-Id: "Lucretia" writes: > One of the things I need to know how to achieve is having a single > specification but different bodies, to create a set of similar shared > libraries. Excellent idea. > So I may have a directory structure like this: > > vector.ads > i386/vector.adb > i386/libvector.so > sse/vector.adb > sse/libvector.so > mmx/vector.adb > mmx/libvector.so Locating the object files with the source files is in general a bad idea, but not relevant to this discussion. > Now, I could export a bunch of C functions and use dlopen/dlsym, etc. > but this isn't the best way and it doesn't allow you to use your Ada > libs the way you want to. Also it would make the types slow to use if > they had to go through C constructors and interfaces (like you would a > C++ shared library). C doesn't have 'constructors', so I don't know what you mean here. If you want the main program to choose which library implementation to use at run time, then dynamic library linking is the only option. This would make sense for a program that could take advantage of different flavors of x86, as you describe above. > I have just created a test program which creates 2 shared libs (in > separate directories with separate makefiles) and then created adalib > and adainclude directories in which the lib, ali and ads files were > linked to. I then built the test app which linked to the files in > adalib and adainclude. I could then use a symlink to change the library > used. This works, but I'm not too sure if it's the correct way to do > this. It's one valid way, and has the advantage of being compiler independent. But it isn't operating system independent; you can't do this on Windows. > Has anyone else done this sort of thing with GNAT? I use GNAT project files for this; one project file per target. The Source_Dirs value specifies what Ada bodies to use, by specifying the directory search path. All objects are placed in one build directory; one build directory per target. -- -- Stephe