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 12 1778
"Joseph Seigh" <js*******@xemaps.com> 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?
Run-time is probably not an issue, but a C++ library is probably
missing. If it's gcc/g++ you're using, try linking using g++.
Compiling the C program as a C++ program seems to work but I'd rather have the library look like a plain C library.
Why?
On Wed, 19 Jan 2005 20:31:59 -0500, Victor Bazarov <v.********@comAcast.net> wrote: "Joseph Seigh" <js*******@xemaps.com> wrote... Compiling the C program as a C++ program seems to work but I'd rather have the library look like a plain C library.
Why?
So the library can have a C api. It's easier to write it in C++
since I have the C++ classes to do it are already written. I could
rewrite the C++ classes in pseudo object oriented C code but that
would be pretty tedious considering the C++ classes are smart pointer
classes.
--
Joe Seigh
"Joseph Seigh" <js*******@xemaps.com> wrote... On Wed, 19 Jan 2005 20:31:59 -0500, Victor Bazarov <v.********@comAcast.net> wrote:
"Joseph Seigh" <js*******@xemaps.com> wrote...
Compiling the C program as a C++ program seems to work but I'd rather have the library look like a plain C library.
Why?
So the library can have a C api. It's easier to write it in C++ since I have the C++ classes to do it are already written. I could rewrite the C++ classes in pseudo object oriented C code but that would be pretty tedious considering the C++ classes are smart pointer classes.
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++?
On Wed, 19 Jan 2005 21:17:46 -0500, Victor Bazarov <v.********@comAcast.net> wrote: "Joseph Seigh" <js*******@xemaps.com> wrote... On Wed, 19 Jan 2005 20:31:59 -0500, Victor Bazarov <v.********@comAcast.net> wrote: Why?
So the library can have a C api. It's easier to write it in C++ since I have the C++ classes to do it are already written. I could rewrite the C++ classes in pseudo object oriented C code but that would be pretty tedious considering the C++ classes are smart pointer classes.
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. The implication here is
I should write libraries in C to begin with since I can use them
to write either C or C++ applications or libraries, but the converse
is not true. Which is too bad since I tend towards OO in design and
would rather not write everything twice, once in C and once in C++.
--
Joe Seigh
"Joseph Seigh" <js*******@xemaps.com> wrote... [..] The implication here is I should write libraries in C to begin with since I can use them to write either C or C++ applications or libraries, but the converse is not true. Which is too bad since I tend towards OO in design and would rather not write everything twice, once in C and once in C++.
I sympathise, believe me. But it seems that even if you "limit"
yourself to doing only C++-targeted libraries, you're not going
to miss too big a segment of the market.
Joseph Seigh wrote: Victor Bazarov wrote:
Joseph Seigh wrote:
Victor Bazarov wrote:
Why?
So the library can have a C api. It's easier to write it in C++ since I have the C++ classes to do it are already written. I could rewrite the C++ classes in pseudo object oriented C code but that would be pretty tedious considering the C++ classes are smart pointer classes.
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. The implication here is I should write libraries in C to begin with since I can use them to write either C or C++ applications or libraries, but the converse is not true. Which is too bad since I tend towards OO in design and would rather not write everything twice, once in C and once in C++.
I think that you may be confused.
You can write a C library that you can compile
with either a C compiler or a C++ compiler.
You could have one object code library archive for C programmers
and a different object code library archive for C++ programmers
both of which are derived from exactly the same source code repository.
On Wed, 19 Jan 2005 22:38:59 -0500, Victor Bazarov <v.********@comAcast.net> wrote: "Joseph Seigh" <js*******@xemaps.com> wrote... [..] The implication here is I should write libraries in C to begin with since I can use them to write either C or C++ applications or libraries, but the converse is not true. Which is too bad since I tend towards OO in design and would rather not write everything twice, once in C and once in C++.
I sympathise, believe me. But it seems that even if you "limit" yourself to doing only C++-targeted libraries, you're not going to miss too big a segment of the market.
It's multithreading stuff which mostly gets done in C at this point.
In this case, it's form of proxy GC based on atomic_ptr and I was
trying to put the api for it in the same form as the RCU for preemptive
user threads api so you could use either without changing code logic.
Let's you do things like AB testing. The atomic_ptr stuff runs faster
but that's on a uniprocessor. Actually, it's an ABC test, C is using
mutexes which is way slower.
--
Joe Seigh
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?
You need to perform the link step with a C++ aware tool,
typically with the C++ compiler. This has the fact of linking
the C++ standard library and possibly other stuff like
instantiating necessary templates.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting
Joseph Seigh wrote: On Wed, 19 Jan 2005 21:17:46 -0500, Victor Bazarov <v.********@comAcast.net> wrote:
"Joseph Seigh" <js*******@xemaps.com> wrote... On Wed, 19 Jan 2005 20:31:59 -0500, Victor Bazarov <v.********@comAcast.net> wrote:
Why?
So the library can have a C api. It's easier to write it in C++ since I have the C++ classes to do it are already written. I could rewrite the C++ classes in pseudo object oriented C code but that would be pretty tedious considering the C++ classes are smart pointer classes.
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.
--
Karl Heinz Buchegger kb******@gascad.at
On Thu, 20 Jan 2005 14:28:42 +0100, Karl Heinz Buchegger <kb******@gascad.at> wrote: Joseph Seigh wrote: On Wed, 19 Jan 2005 21:17:46 -0500, Victor Bazarov <v.********@comAcast.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
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
> 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
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...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
| |