473,881 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling C++ from C

I'm trying to write some C++ library routines callable by C.
The functions are declared extern "C" but I'm getting the
loader complaining it can't resolve new() and delete(). Am I
just missing a library or is the C++ runtime environment
also an issue? Compiling the C program as a C++ program
seems to work but I'd rather have the library look like
a plain C library.

--
Joe Seigh
Jul 22 '05
12 1845
On Thu, 20 Jan 2005 14:28:42 +0100, Karl Heinz Buchegger <kb******@gasca d.at> wrote:
Joseph Seigh wrote:

On Wed, 19 Jan 2005 21:17:46 -0500, Victor Bazarov <v.********@com Acast.net> wrote:
> Let me get this straight. The library has a C interface. But it'll
> be impossible to use from C due to the same problem you yourself
> encountered (missing libraries when linking). So, it will only be
> useful within a C++ project/program. Why not do the users of it
> a favour and leave it C++?
>

So the library can have wider application.


But it can't.
There is no way around it. If it is implemented in C++, then the user
of your library has no other choice then to link the C++ runtime in,
even if he is programming in C.
Here is the deal: What if I have a C compiler only? Then you sold
me a library which is useless for me because I cannot link to it
because of the missing C++ runtime library. So it turns out that
I need to by the C++ compiler (from the same vendor and hopefully
their C library and C++ library are compatible) also, just in order
to link to your library. But then: what is hindering me to use the
C++ compiler in the first place? But then the next question is:
If I am limited to C++ anyway, why did you restrict yourself to
a C API only?

See. When using C++ as implementation language with a C style
interface you have gained nothing et all. I am still forced
to use a C++ compiler.


You're missing the point. The bulk of the applications that would
use the api are written in C. If I restrict the api to C++, I lose
most of those applications since most multi-threading applications
are written in C.

The stuff I'm planning to do is here
http://atomic-ptr-plus.sourceforge.net/

subject to change. I'll have to seriously consider rewriting atomic_ptr
in C. It'd be a lot more awkard to use but it might be worth it to
avoid C++ controversy.

--
Joe Seigh
Jul 22 '05 #11
Joseph Seigh wrote:
I'm trying to write some C++ library routines callable by C.
The functions are declared extern "C" but I'm getting the
loader complaining it can't resolve new() and delete(). Am I
just missing a library or is the C++ runtime environment
also an issue? Compiling the C program as a C++ program
seems to work but I'd rather have the library look like
a plain C library.


If you're compiling C++, you'll have to include the C++ Standard
at some point. Now, you're getting close to off-topic because
you're building something without a main(), but anyway: when
compiling a DLL you end up with two link steps. If you can't
include the C++ lib in the second (dynamic) link fase, you
must link it in the first (static) link fase.

Of course, no guarantees yet, libraries are not yet in ISO C++,
and mixed-lang programming is always implementation-defined.
Regards,
Michiel Salters

Jul 22 '05 #12
> I'm trying to write some C++ library routines callable by C.
The functions are declared extern "C" but I'm getting the
loader complaining it can't resolve new() and delete(). Am I
just missing a library or is the C++ runtime environment
also an issue? Compiling the C program as a C++ program
seems to work but I'd rather have the library look like
a plain C library.


Would you like to apply the techniques that are described by Matthew Wilson in the
sections "7.4 I Can C Clearly Now" and "7.4.4 Getting a Handle on C++ Classes" of the book
"Imperfect C++" (ISBN 0-321-22877-4) for your evolving library?
http://atomic-ptr-plus.sourceforge.net/

Regards,
Markus
Jul 23 '05 #13

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

Similar topics

1
2333
by: Asapi | last post by:
1. Are linkage convention and calling convention referring to the same thing? 2. Does calling convention differ between languages C and C++? 3. How does calling convention differ between static and non-static class member function? 4. Could it be possible to specify different calling convention for each "global" or each class member function? Even in a single file scope?
8
2972
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int p3); The parameters here can be read either in the forward order from p1 till p3 or reverse order from p3 till p1. Can anyone explain what is the advantage/disadvantage of either of
7
6611
by: Klaus Friese | last post by:
Hi, i'm currently working on a plugin for Adobe InDesign and i have some problems with that. I'm not really a c++ guru, maybe somebody here has an idea how to solve this. The plugin is written in C++ and it's calling a java application. This application displays a window and pushing a button is calling back the c++-plugin again.
5
3447
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
3
9113
by: Mike | last post by:
Timeout Calling Web Service I am calling a .NET 1.1 web service from an aspx page. The web service can take several minutes to complete its tasks before returning a message to the aspx page. If the web service is taking a long time to complete, the aspx page returns a ‘The operation has timed-out.’ Message to the web browser after 100 seconds. I’ve added: <httpRuntime executionTimeout="300" /> to the web.config files
2
3155
by: Geler | last post by:
A theoretical question: Sorry if its a beginner question. Here is a quote from the MSDN explaning the C/C++ calling convention.. It demonstrates that the calling function is responsible to clean the stack pointer and it does it by the command "add esp,8" after returning from the called function. My questions: 1. Is the stack pointer common in a certain thread(or process)? 2. How does the called function get the parameters, is it by...
47
5004
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both and my c++ code should call c code.but when i tried to call a function in c code externing that function in my c++ code, i am getting unresolved external symbol error. Whatever i try its giving more and more errrors...so is it possible to merge 2...
7
2696
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file name based on the name of the VB6 application. A second choice would be a file name based on the # COM interface assembly. I have tried calling Assembly.GetCallingAssembly() but this fails when I use the VB6 client. Is there a way to get this...
10
3275
by: sulekhasweety | last post by:
Hi, the following is the definition for calling convention ,which I have seen in a text book, can anyone give a more detailed explanation in terms of ANSI - C "the requirements that a programming system places on how a procedure is called and how data is passed between a calling program and procedures are called calling conventions"
0
9776
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
11096
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...
0
10716
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10812
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
10400
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...
0
9552
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7953
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
7108
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();...
2
4194
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.