473,785 Members | 3,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1679
On Jul 5, 1:01 pm, "b...@blah. com" <GrahamJWa...@g mail.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 objektorientier ter Datenverarbeitu ng
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...@g mail.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.c om (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...@g mail.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...@g mail.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 objektorientier ter Datenverarbeitu ng
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.c om" 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.c om (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.c om/c++-faq-lite/how-to-post.html>
Jul 6 '07 #8

"bo*@blah.c om" <Gr**********@g mail.comwrote in message
news:11******** **************@ c77g2000hse.goo glegroups.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
4258
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 6.0-7.1).. Note, that basically I don't need an "extern C" linkage, I just need to define a type to cast a resolved function address.. Any ideas? Basically , I need something like this..
1
2651
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
6199
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: // main.cpp // This is defined in a C module extern "C" void fake_qsort(void*, std::size_t, std::size_t, int (*compare)(const void*, const void*));
12
2730
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 linkage? Not much on this in the FAQ or tutorials.
19
3860
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 storage-class specifier. My (little) C experience tells me that an object with "extern" is to let the linker knows that the object is referencing the object defined in somewhere, and this "somewhere" object does not have the storage-class specifier...
4
4759
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 global function with the extern "C" prefix. I was leaning toward using the static method approach until I saw a posting that said compatibility between static C++ functions and C is not guaranteed in the respective language standards. This made me...
4
6260
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 functions written in the "SomeLanguage". But I am quite confused what information does the linkage directive tells the compiler.The "generated" function name? The way the arguments are ordered?Or something else? And I am still wondering why extern...
17
3783
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, that presents a single function declared: int foo_function(int x); The world is simple and all the small creatures rejoice in its simplicity.
2
1383
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 include (template?) classes (e.g. string) in exposed API Are there other ex/implicit restrictions I may have missed ?
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10085
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.