Hi,
I am running into a problem where I am trying to import C DLL into a
Visual C++ 2008 application. The functions in the C DLL are obviously
not name mangled (verified using Dependency Walker). When I try to use
any of the functions from the DLL, VC++ mangles these names (or so it
looks like) and complains that it can't link to mangled versions of
the function names. To avoid this I've figured that I need to declare
the functions I would like to use from the DLL as follows:
extern "C"
{
void Py_Initialize(v oid);
}
Is there any easier way of doing this than to declare all the
functions in the DLL using extern "C"?
Thanks
Jaco 10 4077
On Jul 23, 1:35*pm, Jaco Naude <naude.j...@gma il.comwrote:
Hi,
I am running into a problem where I am trying to import C DLL into a
Visual C++ 2008 application. The functions in the C DLL are obviously
not name mangled (verified using Dependency Walker). When I try to use
any of the functions from the DLL, VC++ mangles these names (or so it
looks like) and complains that it can't link to mangled versions of
the function names. To avoid this I've figured that I need to declare
the functions I would like to use from the DLL as follows:
extern "C"
{
* * void Py_Initialize(v oid);
}
Is there any easier way of doing this than to declare all the
functions in the DLL using extern "C"?
Thanks
Jaco
You could change your C code file extension from .c to .cpp.
But this is not very practical.
Daniel.
Jaco Naude wrote:
Hi,
I am running into a problem where I am trying to import C DLL into a
Visual C++ 2008 application. The functions in the C DLL are obviously
not name mangled (verified using Dependency Walker). When I try to use
any of the functions from the DLL, VC++ mangles these names (or so it
looks like) and complains that it can't link to mangled versions of
the function names. To avoid this I've figured that I need to declare
the functions I would like to use from the DLL as follows:
extern "C"
{
void Py_Initialize(v oid);
}
Is there any easier way of doing this than to declare all the
functions in the DLL using extern "C"?
That's the standard way of informing the C++ compiler functions have C
linkage.
--
Ian Collins.
Jaco Naude <na********@gma il.comwrites:
Hi,
I am running into a problem where I am trying to import C DLL into a
Visual C++ 2008 application. The functions in the C DLL are obviously
not name mangled (verified using Dependency Walker). When I try to use
any of the functions from the DLL, VC++ mangles these names (or so it
looks like) and complains that it can't link to mangled versions of
the function names. To avoid this I've figured that I need to declare
the functions I would like to use from the DLL as follows:
extern "C"
{
void Py_Initialize(v oid);
}
Is there any easier way of doing this than to declare all the
functions in the DLL using extern "C"?
Yes:
#define C(X) extern "C" { X; }
C(void Py_Initialize(v oid))
C(void Py_Middlize(voi d))
C(void Py_Terminalize( void))
Assuming typing 'C( )' is easier than typing 'extern "C"{ }'...
--
__Pascal Bourguignon__
On 2008-07-23 06:35:00 -0400, Jaco Naude <na********@gma il.comsaid:
>
I am running into a problem where I am trying to import C DLL into a
Visual C++ 2008 application. The functions in the C DLL are obviously
not name mangled (verified using Dependency Walker).
Last time I looked, VC++ did mangle names when compiling C code. It
sticks an underscore on the front.
When I try to use
any of the functions from the DLL, VC++ mangles these names
Well, it mangles them differently from the way they're mangled when
they're compiled as C code.
(or so it
looks like) and complains that it can't link to mangled versions of
the function names. To avoid this I've figured that I need to declare
the functions I would like to use from the DLL as follows:
extern "C"
{
void Py_Initialize(v oid);
}
Is there any easier way of doing this than to declare all the
functions in the DLL using extern "C"?
No, that's what extern "C" is for.
Note that this problem really has nothing to do with the use of DLLs,
except that that's where you happened to notice it. It comes up
whenever you need to link C code with C++ code. You have to tell the
compiler that those things were compiled as C so that it can generate
code with the correct calling convention (which can include more than
just changing how the names are mangled).
--
Pete
Roundhouse Consulting, Ltd. ( www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
( www.petebecker.com/tr1book)
On Jul 23, 1:00*pm, Pete Becker <p...@versatile coding.comwrote :
On 2008-07-23 06:35:00 -0400, Jaco Naude <naude.j...@gma il.comsaid:
I am running into a problem where I am trying to import C DLL into a
Visual C++ 2008 application. The functions in the C DLL are obviously
not name mangled (verified using Dependency Walker).
Last time I looked, VC++ did mangle names when compiling C code. It
sticks an underscore on the front.
*When I try to use
any of the functions from the DLL, VC++ mangles these names
Well, it mangles them differently from the way they're mangled when
they're compiled as C code.
*(or so it
looks like) and complains that it can't link to mangled versions of
the function names. To avoid this I've figured that I need to declare
the functions I would like to use from the DLL as follows:
extern "C"
{
* * void Py_Initialize(v oid);
}
Is there any easier way of doing this than to declare all the
functions in the DLL using extern "C"?
No, that's what extern "C" is for.
Note that this problem really has nothing to do with the use of DLLs,
except that that's where you happened to notice it. It comes up
whenever you need to link C code with C++ code. You have to tell the
compiler that those things were compiled as C so that it can generate
code with the correct calling convention (which can include more than
just changing how the names are mangled).
--
* Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
Thanks for all the replies. Seems like thats the way to do it. I'll go
with the #define C(X) extern "C" { X; } option for now.
Thanks again.
On Jul 23, 12:53 pm, p...@informatim ago.com (Pascal J. Bourguignon)
wrote:
Jaco Naude <naude.j...@gma il.comwrites:
I am running into a problem where I am trying to import C DLL into a
Visual C++ 2008 application. The functions in the C DLL are obviously
not name mangled (verified using Dependency Walker). When I try to use
any of the functions from the DLL, VC++ mangles these names (or so it
looks like) and complains that it can't link to mangled versions of
the function names. To avoid this I've figured that I need to declare
the functions I would like to use from the DLL as follows:
extern "C"
{
void Py_Initialize(v oid);
}
Is there any easier way of doing this than to declare all the
functions in the DLL using extern "C"?
Yes:
#define C(X) extern "C" { X; }
C(void Py_Initialize(v oid))
C(void Py_Middlize(voi d))
C(void Py_Terminalize( void))
Assuming typing 'C( )' is easier than typing 'extern "C"{ }'...
That is, quite frankly, horrible. And what happens if you use C
as a name somewhere? Not to mention that the person reading the
code will have no idea what is going on.
With any decent editor, you can set up an abbreviation so that
you just have to type C to get your extern "C", if it is really
typing which is bothering you. (Although seriously, how long
does it take to type `extern "C"?) More generally, however, the
usual solution is to define an extern "C" block for the entire
library, e.g.:
#ifdef __cplusplus
extern "C" {
#endif
void Py_Initialize( void ) ;
void Py_Middlize( void ) ;
// ...
#ifdef __cplusplus
}
#endif
(I don't normally approve of #ifdef, but this is one of those
cases where it is so ubiquious, any other solution would cause
the reader to wonder why it wasn't done this way.)
--
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
In article <e6************ *************** *******@y38g200 0hsy.googlegrou ps.com>,
Jaco Naude <na********@gma il.comwrote:
>Thanks for all the replies. Seems like thats the way to do it. I'll go with the #define C(X) extern "C" { X; } option for now.
If I has no compelling reason to do so, I would not use a macro,
and probably not one named C however appropriate that may seem,
to establish extern "C", but that's just me. It implies a non-C too
(or at least an empty C(X), and I think I'd rather prefer to use
a more traditional "co-ed header" file ala the discussion found at http://www.comeaucomputing.com/techtalk/#externC ).
--
Greg Comeau / 4.3.10.1 with C++0xisms now in beta!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
On 23 Temmuz, 13:35, Jaco Naude <naude.j...@gma il.comwrote:
Hi,
I am running into a problem where I am trying to import C DLL into a
Visual C++ 2008 application. The functions in the C DLL are obviously
not name mangled (verified using Dependency Walker). When I try to use
any of the functions from the DLL, VC++ mangles these names (or so it
looks like) and complains that it can't link to mangled versions of
the function names. To avoid this I've figured that I need to declare
the functions I would like to use from the DLL as follows:
extern "C"
{
* * void Py_Initialize(v oid);
}
Is there any easier way of doing this than to declare all the
functions in the DLL using extern "C"?
Thanks
Jaco
Change "Project options" --"Configurat ion Properties" --C/C++ -->
Advanced --Compile as
to "Compile as C Code (/TC)" and remove the " Extern "C" "
declarations
thats all folks ! ;)
No any other changes required...
_______________ ___ http://www.invenoo.com
On Jul 23, 11:36 pm, Jaco Naude <naude.j...@gma il.comwrote:
>
Thanks for all the replies. Seems like thats the way to do it. I'll go
with the #define C(X) extern "C" { X; } option for now.
That's the worst possible solution.
Don't forget you can put multiple prototypes inside a single extern
"C" {} block, so you only have to type it once rather than every time
for that horrible macro. That's how system headers are shared between
C and C++.
Ian. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steven Bethard |
last post by:
Philippe C. Martin wrote:
> class Debug_Stderr:
> __m_text = ''
> __m_log_text = None
> __m_dbg = None
> __m_refresh_count = 0
<rant>
I don't see the benefit in 99.9% of cases for making class variables
|
by: Tim Slattery |
last post by:
Does the C++ language standard mandate a particular name-mangling
method?
I'm trying to use the Entrust toolkit to create a C++ program that
encrypts and decrypts files. Entrust supplies header files defining
their objects and functions, and *.so files (I'm on a Sun Sparc
machine running Solaris) containing the implementation of the
functions.
I'm compiling with the GNU g++ compiler. According to the
|
by: yyy |
last post by:
my question is rather theoretical than practical in the pure programming
aspect...
is "name mangling" the same as "name decorating" ?
browsing the web, you might find multiple people saying "yes", but i
vaguely remember having read that it's not exactly like that
one might say that "name mangling" is a part of c++ compiler specification
and is a naming scheme to support function overloading
|
by: Bruno van Dooren |
last post by:
Hi all,
i have developed a class that has a member called 'PostMessage'
if i only reference this member from within the class context, there is no
problem, but if i trie to execute it as a method, i get the error
error LNK2019: unresolved external symbol "public: void __thiscall
MessageQ::PostMessageA(struct t_Message *)"
(?PostMessageA@MessageQ@@QAEXPAUt_Message@@@Z) referenced in function
|
by: David Wade |
last post by:
Folks,
Does any one know of any "name mangling" software that allows standard C
with long names to be linked? Any suggestions for a better place to look? I
have tried putting various searchs into google to no avail.
Dave.
| |
by: Subhransu Sahoo |
last post by:
Hi All,
Does the C++ standard tell function overloading can't be done with the
return types of two functions ? If so, is it true that the name
mangling scheme does not take the return type into account ?I know that
C++ standard does not tell anything about name mangling and only talks
bout function overloading. But, I have observed that the Metrowerks
Code Warrior compiler does take return type into the mangling scheme.
Is it not a bug...
|
by: sam_cit |
last post by:
Hi Everyone,
I read somwhere that c++ compiler does name mangling of functions
which is why c source code can't invoke functions from object files
that were generated using c++ compiler. Can anyone tell in detail as to
what name mangling is all about?
|
by: jason.cipriani |
last post by:
Does anybody know if C++0x is going to change C++ name mangling at
all? Such as, standardizing name mangling instead of leaving it up to
the compiler?
Jason
|
by: Megalo |
last post by:
why not make "name mangling" of C++ standard so should be possible
to call
the classes and the functions of C++ from other C++ compiler
thanks
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |