Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Standalone C wrapper to C++ library

Reply
Thread Tools

Standalone C wrapper to C++ library

 
 
deech
Guest
Posts: n/a
 
      05-07-2013
Hi all,
I am not an experienced C developer and would like to know if there are good resources for, or better yet real-world examples of, wrapping a C++ library in C such that application written using it don't need to have the underlying C++ library.

The best resource [1] I've found shows me how to create a shared library which seems to requires the C++ library to be installed.

Thanks for your help!
-deech

[1] http://losinggeneration.homelinux.or...indings-for-c/
 
Reply With Quote
 
 
 
 
Tiib
Guest
Posts: n/a
 
      05-08-2013
On Wednesday, 8 May 2013 01:51:45 UTC+3, deech wrote:
> Hi all,
>
> I am not an experienced C developer and would like to know if there are
> good resources for, or better yet real-world examples of, wrapping a
> C++ library in C such that application written using it don't need to
> have the underlying C++ library.
>
> The best resource [1] I've found shows me how to create a shared
> library which seems to requires the C++ library to be installed.


Yes ... but how exactly you imagine it using something that is not
present? Application can load shared library dynamically and if it
is not present (the dynamic loading failed) then tell that it is
unavailable/not installed ... but actual usage ... that should
feel impossible even for inexperienced.

 
Reply With Quote
 
 
 
 
deech
Guest
Posts: n/a
 
      05-08-2013
I think I wasn't clear. I meant that I want to be able to distribute the application written with the c wrapper as a fat executable so that the user can run it without having to install anything else.

Thanks for clarifying.
-deech

On Tuesday, May 7, 2013 7:09:44 PM UTC-5, Tiib wrote:
> On Wednesday, 8 May 2013 01:51:45 UTC+3, deech wrote:
>
> > Hi all,

>
> >

>
> > I am not an experienced C developer and would like to know if there are

>
> > good resources for, or better yet real-world examples of, wrapping a

>
> > C++ library in C such that application written using it don't need to

>
> > have the underlying C++ library.

>
> >

>
> > The best resource [1] I've found shows me how to create a shared

>
> > library which seems to requires the C++ library to be installed.

>
>
>
> Yes ... but how exactly you imagine it using something that is not
>
> present? Application can load shared library dynamically and if it
>
> is not present (the dynamic loading failed) then tell that it is
>
> unavailable/not installed ... but actual usage ... that should
>
> feel impossible even for inexperienced.


 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      05-08-2013
On 05/07/2013 06:51 PM, deech wrote:
> Hi all, I am not an experienced C developer and would like to know if
> there are good resources for, or better yet real-world examples of,
> wrapping a C++ library in C such that application written using it
> don't need to have the underlying C++ library.


There's a fundamental conflict built into your concept. You'll have to
resolve that conflict before you can do anything useful. Do you want to
wrap the C++ library, or replace it? A wrapper, by definition, calls the
function that it is a wrapper for; you can't have a working wrapper if
you don't have a working copy of the wrapped function.

> The best resource [1] I've found shows me how to create a shared
> library which seems to requires the C++ library to be installed.


Yes, that's normally the case. If that's unacceptable, then your only
alternative is to replace the library, rather than provide wrappers for
it. In general, that's going to involve a lot more work.
--
James Kuyper
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      05-08-2013
deech wrote:
> I think I wasn't clear. I meant that I want to be able to distribute
> the application written with the c wrapper as a fat executable so
> that the user can run it without having to install anything else.


Please don't top-post!

In general, if the library is a dynamic library you can't include it in
a fat executable. If it is a static library, then yes you can include it.

--
Ian Collins
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      05-08-2013
On 05/07/2013 10:19 PM, deech wrote:
> I think I wasn't clear. I meant that I want to be able to distribute
> the application written with the c wrapper as a fat executable so
> that the user can run it without having to install anything else.
>
> Thanks for clarifying.
> -deech
>
> On Tuesday, May 7, 2013 7:09:44 PM UTC-5, �� Tiib wrote:
>> On Wednesday, 8 May 2013 01:51:45 UTC+3, deech wrote:
>>> Hi all,
>>>
>>> I am not an experienced C developer and would like to know if
>>> there are
>>> good resources for, or better yet real-world examples of,
>>> wrapping a
>>> C++ library in C such that application written using it don't
>>> need to
>>> have the underlying C++ library.
>>>
>>> The best resource [1] I've found shows me how to create a shared
>>> library which seems to requires the C++ library to be
>>> installed.


Yes, the C++ libraries you're wrapping must be present when you create
your program. Whether they also need to be present when the program is
executed depends upon how your code is linked. The way to link it to
create a "fat executable" is different on each of the operating systems
I'm familiar with, so you'll need to identify which one you're using.
Once you have, the best place to get an answer to your question will be
a forum devoted to that operating system. comp.lang.c isn't that forum,
no matter which OS you're using.
--
James Kuyper
 
Reply With Quote
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      05-08-2013
James Kuyper <(E-Mail Removed)> wrote:
> On 05/07/2013 06:51 PM, deech wrote:
>> Hi all, I am not an experienced C developer and would like to know if
>> there are good resources for, or better yet real-world examples of,
>> wrapping a C++ library in C such that application written using it
>> don't need to have the underlying C++ library.


> There's a fundamental conflict built into your concept. You'll have to
> resolve that conflict before you can do anything useful. Do you want to
> wrap the C++ library, or replace it? A wrapper, by definition, calls the
> function that it is a wrapper for; you can't have a working wrapper if
> you don't have a working copy of the wrapped function.


Well, the wrapped function doesn't have to call (directly or
indirectly) C++ library routines. Most will, but some might not, and
it might not be so hard to change the calls, for example to C library
calls instead.

>> The best resource [1] I've found shows me how to create a shared
>> library which seems to requires the C++ library to be installed.


> Yes, that's normally the case. If that's unacceptable, then your only
> alternative is to replace the library, rather than provide wrappers for
> it. In general, that's going to involve a lot more work.


In general, but maybe not always.

-- glen
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      05-08-2013
On 05/07/2013 11:49 PM, glen herrmannsfeldt wrote:
> James Kuyper <(E-Mail Removed)> wrote:
>> On 05/07/2013 06:51 PM, deech wrote:
>>> Hi all, I am not an experienced C developer and would like to know if
>>> there are good resources for, or better yet real-world examples of,
>>> wrapping a C++ library in C such that application written using it
>>> don't need to have the underlying C++ library.

>
>> There's a fundamental conflict built into your concept. You'll have to
>> resolve that conflict before you can do anything useful. Do you want to
>> wrap the C++ library, or replace it? A wrapper, by definition, calls the
>> function that it is a wrapper for; you can't have a working wrapper if
>> you don't have a working copy of the wrapped function.

>
> Well, the wrapped function doesn't have to call (directly or
> indirectly) C++ library routines. Most will, but some might not, ...


Huh? It doesn't matter whether the wrapped function calls other C++
library routines; the fact that the wrapped function is itself a C++
library routine is sufficient for there to be a problem. If the library
containing the wrapped function is not available, the wrapping function
can't work.

....
> ... and
> it might not be so hard to change the calls, for example to C library
> calls instead.


Well, first he'd have to write C library functions corresponding to the
C++ library functions he wanted to make wrappers for. He didn't indicate
which functions he was thinking of wrapping; he didn't even mention
which library they were from, so we have no way of knowing how difficult
of a task that might be. However, if writing equivalent C code were a
trivial task, I doubt he'd be thinking about using wrappers.

Later messages on another branch of this thread have clarified that his
issue is about the distinction between what, in a unix context, would be
described as static vs. dynamic linking. If the wrapped function is part
of a shared-object C++ library that is dynamically linked, it's a
problem if that library is not installed on on the machine where the
program will be executed. What he describes as a "fat executable"
corresponds to linking in the library statically. The same issue comes
up in other operating systems, but the description above might need
appropriate modifications.
--
James Kuyper
 
Reply With Quote
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      05-08-2013
James Kuyper <(E-Mail Removed)> wrote:
> On 05/07/2013 11:49 PM, glen herrmannsfeldt wrote:
>> James Kuyper <(E-Mail Removed)> wrote:
>>> On 05/07/2013 06:51 PM, deech wrote:
>>>> Hi all, I am not an experienced C developer and would like to know if
>>>> there are good resources for, or better yet real-world examples of,
>>>> wrapping a C++ library in C such that application written using it
>>>> don't need to have the underlying C++ library.


(snip)
>> Well, the wrapped function doesn't have to call (directly or
>> indirectly) C++ library routines. Most will, but some might not, ...


> Huh? It doesn't matter whether the wrapped function calls other C++
> library routines; the fact that the wrapped function is itself a C++
> library routine is sufficient for there to be a problem. If the library
> containing the wrapped function is not available, the wrapping function
> can't work.


OK, I was reading it as "a C++ library", not "the C++ library."
Consider someone writing "a C++ library for numerical integration."
Normally, one won't need to do I/O, and often won't need any
memory allocation, other than local (stack) variables.
In that case, it isn't hard to avoid calling any library routines.

>> ... and
>> it might not be so hard to change the calls, for example to C library
>> calls instead.


One might, for example, call the C malloc() and free() even in C++.

> Well, first he'd have to write C library functions corresponding to the
> C++ library functions he wanted to make wrappers for. He didn't indicate
> which functions he was thinking of wrapping; he didn't even mention
> which library they were from, so we have no way of knowing how difficult
> of a task that might be. However, if writing equivalent C code were a
> trivial task, I doubt he'd be thinking about using wrappers.


(snip on dynamic linking)

-- glen
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      05-08-2013
On 05/08/2013 02:23 PM, glen herrmannsfeldt wrote:
> James Kuyper <(E-Mail Removed)> wrote:
>> On 05/07/2013 11:49 PM, glen herrmannsfeldt wrote:
>>> James Kuyper <(E-Mail Removed)> wrote:
>>>> On 05/07/2013 06:51 PM, deech wrote:
>>>>> Hi all, I am not an experienced C developer and would like to know if
>>>>> there are good resources for, or better yet real-world examples of,
>>>>> wrapping a C++ library in C such that application written using it
>>>>> don't need to have the underlying C++ library.

>
> (snip)
>>> Well, the wrapped function doesn't have to call (directly or
>>> indirectly) C++ library routines. Most will, but some might not, ...

>
>> Huh? It doesn't matter whether the wrapped function calls other C++
>> library routines; the fact that the wrapped function is itself a C++
>> library routine is sufficient for there to be a problem. If the library
>> containing the wrapped function is not available, the wrapping function
>> can't work.

>
> OK, I was reading it as "a C++ library", not "the C++ library."


So was I. He might have been referring to a function from the C++
standard library, or he might not. So long as the library containing the
wrapped function is the same one that he didn't want the wrapping
function to need, the issues are precisely the same either way. I can
make sense of your comments by assuming that you thought they were two
different libraries - is that how you interpreted it?

> Consider someone writing "a C++ library for numerical integration."
> Normally, one won't need to do I/O, and often won't need any
> memory allocation, other than local (stack) variables.
> In that case, it isn't hard to avoid calling any library routines.


True, but if that library included a function template named
numint::Trapezoid_Rule<T>(), and someone wrote a C function named
trapezoid_rule_double() as a wrapper for numint::Trapezoid_Rule<double>,
the wrapper still wouldn't work if the numerical integration library
were unavailable, even if numint::Trapezoid_Rule<double> doesn't call
any library routines. It's the absence of the numerical integration
library that matters, not the details of what
numint::Trapezoid_Rule<double> would have done if the library had been
present.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
same ruby file acting standalone resp. as library Thomas Hafner Ruby 2 04-21-2007 10:42 PM
standalone xml library? Noah Roberts C++ 6 03-25-2005 01:45 PM
Wrapper to speex and ffmpeg library maxwell hammer Python 0 01-17-2004 06:31 AM
C Library Wrapper in C++ Ian C++ 3 10-18-2003 05:23 AM
[Dream] A meta-wrapper module to interface any C dynamic library Francesco Bochicchio Python 6 07-04-2003 05:39 PM



Advertisments