473,396 Members | 2,068 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.

extern "C" and wrapping

bob
Hi,

we're faced with a horrible scenario whereby we are not able to access
exported classes in a DLL due to cross compiler issues.

Traditional approaches such as using extern "C" and LoadLibrary
(nothing to do with C++ I know but I'll get to my question... :).
Anyways, we need to access our exported objects and the only safe
route I know to get to the destination dll/lib from our client (not in
same environment) is by using extern "C" for various functions.

However doing this I lose all my object orientation. Is there any
pattern/approach out there available that will allow me to use extern
"C" such that its implementation gives me access to the C++ objects
implemented in the target DLL/LIB. I think this must be an age old
problem I'm just stumped by it and I honestly think somebody has a
clever pattern/approach to this that will allow me to bypass the
problem at hand.

I obviously can't replace all my objects method calls into extern "C"
functions and in paralell this must scale. I.E as new functions/
classes are added , I need to be able to access them without too much
pain, extra work.

Does anybody know of such a solution? Or is this unsolveable...i.e.
I'm asking too much.

thanks for any assistance.

GrahamO

Jul 5 '07 #1
8 1652
On Jul 5, 1:01 pm, "b...@blah.com" <GrahamJWa...@gmail.comwrote:
we're faced with a horrible scenario whereby we are not able to access
exported classes in a DLL due to cross compiler issues.
Traditional approaches such as using extern "C" and LoadLibrary
(nothing to do with C++ I know but I'll get to my question... :).
Anyways, we need to access our exported objects and the only safe
route I know to get to the destination dll/lib from our client (not in
same environment) is by using extern "C" for various functions.
However doing this I lose all my object orientation. Is there any
pattern/approach out there available that will allow me to use extern
"C" such that its implementation gives me access to the C++ objects
implemented in the target DLL/LIB. I think this must be an age old
problem I'm just stumped by it and I honestly think somebody has a
clever pattern/approach to this that will allow me to bypass the
problem at hand.
I obviously can't replace all my objects method calls into extern "C"
functions and in paralell this must scale. I.E as new functions/
classes are added , I need to be able to access them without too much
pain, extra work.
Does anybody know of such a solution? Or is this unsolveable...i.e.
I'm asking too much.
The way I usually handle plugins and such is to declare a
single, extern "C" function which returns a pointer to the
abstract base of a factory class; I then call member functions
on the factory class to get the objects I want (or do anything
else in the plugin, for that matter).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 5 '07 #2
On Thu, 05 Jul 2007 08:08:57 -0700, James Kanze wrote:
>On Jul 5, 1:01 pm, "b...@blah.com" <GrahamJWa...@gmail.comwrote:
>we're faced with a horrible scenario whereby we are not able to access
exported classes in a DLL due to cross compiler issues.

The way I usually handle plugins and such is to declare a
single, extern "C" function which returns a pointer to the
abstract base of a factory class; I then call member functions
on the factory class to get the objects I want (or do anything
else in the plugin, for that matter).
"cross compiler issues" probably means that he wants to combine C++
code compiled by two compilers which use different name mangling. I
guess he is doomed.
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Jul 5 '07 #3
bob
Hi Roland, and thanks James for your reply.
Roland, do you mean the approach is "doomed" .... i.e. even if we pass
link and get and exe with some functions/classes available... we will
ultimately hit a large dirty wall? Or do you use 'doomed' in the sense
that we have no other choice but providing we can do the mapping,
we'll be ok?

I'd like to know if our approach is destined for failure or is it the
case that if we get the symbols mapped and linked we should be ok.

OK put it this way... has anybody else out there done this?

thanks much. We have a very importance decision to make in the next 4
hours!! :(

GrahamO

On Jul 5, 8:32 pm, rpbg...@yahoo.com (Roland Pibinger) wrote:
On Thu, 05 Jul 2007 08:08:57 -0700, James Kanze wrote:
On Jul 5, 1:01 pm, "b...@blah.com" <GrahamJWa...@gmail.comwrote:
we're faced with a horrible scenario whereby we are not able to access
exported classes in a DLL due to cross compiler issues.
The way I usually handle plugins and such is to declare a
single, extern "C" function which returns a pointer to the
abstract base of a factory class; I then call member functions
on the factory class to get the objects I want (or do anything
else in the plugin, for that matter).

"cross compiler issues" probably means that he wants to combine C++
code compiled by two compilers which use different name mangling. I
guess he is doomed.

--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch

Jul 6 '07 #4
On Jul 6, 10:55 am, "b...@blah.com" <GrahamJWa...@gmail.comwrote:
Hi Roland, and thanks James for your reply.
Roland, do you mean the approach is "doomed" .... i.e. even if we pass
link and get and exe with some functions/classes available... we will
ultimately hit a large dirty wall? Or do you use 'doomed' in the sense
that we have no other choice but providing we can do the mapping,
we'll be ok?
Doomed means that it won't work. The approach I suggested will
allow you to get around the mangling problem (since only
function names are mangled, and you only call functions through
pointers in the vtable). With the result that everything will
compile and link just fine, but may core dump on execution,
because different compilers lay out the vtable differently.
I'd like to know if our approach is destined for failure or is
it the case that if we get the symbols mapped and linked we
should be ok.
All C++ must be compiled by the same compiler.

About the only way to get around this is to define a very, very
narrow interface in C, using C style structs, or even better,
serialized data, which you marshall and unmarshall at both ends,
and then take whatever steps are necessary on your platform to
ensure that your dynamicly linked component is autonome. (I
think this is the default for Windows. It takes some explicit
precautions under Unix.)
OK put it this way... has anybody else out there done this?
Some applications do use plug-in's, yes.
thanks much. We have a very importance decision to make in the
next 4 hours!! :(
Make it flexible, so you can go back and fix it when it doesn't
work:-).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 6 '07 #5
On Fri, 06 Jul 2007 01:55:15 -0700, "bo*@blah.com" wrote:
>OK put it this way... has anybody else out there done this?
You haven't yet explained what "cross compiler issues" you face. Is it
really a name-mangling problem? Unlikely on Windows. I can only guess
(and my guess may as well be wrong). If it's Windows specific try one
of the Windows programming newsgroups.
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Jul 6 '07 #6
bob
thanks for all the replies.... the issue is precisely differences in
name mangling. Borland mangles differently from ms. We're hacking! :(
thanks for the previous replies. I know have to start looking at some
very serious intelligent and workable solutions. BOOM goes my
weekend! :(
thanks again for any replies.

cheers

G

On Jul 6, 5:06 pm, rpbg...@yahoo.com (Roland Pibinger) wrote:
On Fri, 06 Jul 2007 01:55:15 -0700, "b...@blah.com" wrote:
OK put it this way... has anybody else out there done this?

You haven't yet explained what "cross compiler issues" you face. Is it
really a name-mangling problem? Unlikely on Windows. I can only guess
(and my guess may as well be wrong). If it's Windows specific try one
of the Windows programming newsgroups.

--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch

Jul 6 '07 #7
bo*@blah.com wrote:
Hi Roland, and thanks James for your reply.
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.com/c++-faq-lite/how-to-post.html>
Jul 6 '07 #8

"bo*@blah.com" <Gr**********@gmail.comwrote in message
news:11**********************@c77g2000hse.googlegr oups.com...
Hi,

we're faced with a horrible scenario whereby we are not able to access
exported classes in a DLL due to cross compiler issues.

Traditional approaches such as using extern "C" and LoadLibrary
(nothing to do with C++ I know but I'll get to my question... :).
Anyways, we need to access our exported objects and the only safe
route I know to get to the destination dll/lib from our client (not in
same environment) is by using extern "C" for various functions.

However doing this I lose all my object orientation. Is there any
pattern/approach out there available that will allow me to use extern
"C" such that its implementation gives me access to the C++ objects
implemented in the target DLL/LIB. I think this must be an age old
problem I'm just stumped by it and I honestly think somebody has a
clever pattern/approach to this that will allow me to bypass the
problem at hand.

I obviously can't replace all my objects method calls into extern "C"
functions and in paralell this must scale. I.E as new functions/
classes are added , I need to be able to access them without too much
pain, extra work.

Does anybody know of such a solution? Or is this unsolveable...i.e.
I'm asking too much.

thanks for any assistance.
While dated, the following link may be helpful:

http://www.microsoft.com/msj/archive/S330.aspx

I'd like to imagine that the Borland and MS compilers are a bit more
compatible these days. Whether or not you can get interfaces (that is, Pure
ABC's-Plus) to work reliably across compilers (and who's to say that your
program won't be broken by a vendor change in the future after you've
deployed?), I don't know. There's an old article in MSJ though that had that
goal way back when. I don't remember to what degree they succeeded or what
the final caveats were. The gist is, though, to put "behind the DLL wall"
the C++-isms of the objects (interaces) you get from your extern "C" factory
functions.

(Aside: COM (Component Object Model) provides a Microsoft way of doing
interfaces across tools and programming languages. Not that I'm
recommending/un-recommending it though.)

John

Jul 6 '07 #9

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

Similar topics

4
by: Sergei | last post by:
I ran into this problem. I needed to create an entry for access to a library of functions that are "extern C", and I just can't find the right syntax, if it exists at all ( I am using MSVC...
1
by: terrencel | last post by:
I was told to look at some old C code that was ported to C++. One of the file is like: ========================================= CPPClass* someCPPVar = NULL; extern "C" {
10
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention. Here's a sample of what I want to do: //...
12
by: G Patel | last post by:
I've seen some code with extern modifiers in front of variables declared inside blocks. Are these purely definitions (no definition) or are they definitions with static duration but external...
19
by: ccwork | last post by:
Hi all, I am reading "C: A Reference Manual" 4th ed and I get lost for the "extern". It says that global object without specifying the storage-class specifier will have "extern" as the default...
4
by: kk_oop | last post by:
Hi. I need to write a C++ callback function and register it with a C program. I've read that this can be done if the callback function is a static method. I've also read that I should use a...
4
by: mimi | last post by:
The programmer indicates to the compiler that a function is written in a different programming language using a linkage directives.It is intuitive that extern "SomeLanguage" is used to declare...
17
by: William Pursell | last post by:
I debated whether this belongs in comp.lang.c++, and finally decided that it belongs here, because it really is a C question... Suppose I have a perfectly friendly, harmless library, libfoo,...
2
by: Gray Alien | last post by:
These are the "restrictions" I have come accross when "wrapping up" all function declarations in a header with extern "C": i). Inability to overload functions in exposed API ii). Inability to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.