Generate C wrappers from C++?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Generate C wrappers from C++?

swig

I kind of assumed I could do this, but it is not mentioned.

Can I generate C wrappers of a C++ library with SWIG?

--
 kai



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|

Re: Generate C wrappers from C++?

Marcelo Matus
No, sorry, "C" is not a target language right now (as is
tcl,python,java,csharp, etc, etc).
But people keeps asking for the same, maybe one day we will have a
volunteer to
write a C target module.

Marcelo

[hidden email] wrote:

>I kind of assumed I could do this, but it is not mentioned.
>
>Can I generate C wrappers of a C++ library with SWIG?
>
>  
>



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|

PHP & C++ default arguments

Jeffrey D. Wheelhouse
In reply to this post by swig

Hello,

I'm trying to use Swig to standardize an interface between C++, Python,
and PHP.  The existing C++ interface translates just fine to Python, but
the PHP generation seems to have serious problems with C++ methods with
default parameters:

First problem: if I don't use "-noproxy" I get multiple definitions at
runtime:

Warning: Function registration failed - duplicate name - test in Unknown
on line 0

(These stem from identical lines in the _wrap.cpp file.)

Second problem: if I do use "-noproxy," the resulting code appears to be
valid, but frequently functions with default parameters simply don't get
called. (It doesn't matter whether or not the default parameters are
specified from PHP.)

This seems most pronounced on methods containing a std::string parameter:

==== C++ Header:
class MyTest {
  public:
    void Test(const std::string &st, bool b = false);
};

==== C++ Source:
void MyTest::Test(const std::string &st, bool b) {
  std::cout << "This will never happen: " << st << std::endl;
}

==== PHP Code:
$mytest = new_Mytest();
MyTest_Test($mytest,"Hi!");

==== SWIG file:
%module mytest
%include "std_string.i"
%{
#include "my_test.h"
%}
%include "my_test.h"

In the above example, the body of MyTest::Test will never be called.  If
I change the Test method, either of these will work fine:

void Test(const std::string &st, bool b);  // No default value for b.
void Test(int st, bool b=false); // Not a std::string anymore.

And all of it works fine in Python.  Am I missing something about using
std::string in this context that I could fix to at least get it working
with -noproxy for PHP?

Thanks for any advice!  SWIG seems like a fantastic tool.

Jeff



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|

Re: PHP & C++ default arguments

Kevin Ruland

Jeffrey,

The problem appears to be overloading methods in a class.  I'm taking a
look at it now, and will hopefully have a patch in CVS shortly.

Kevin

Jeffrey D. Wheelhouse wrote:

> Hello,
>
> I'm trying to use Swig to standardize an interface between C++, Python,
> and PHP.  The existing C++ interface translates just fine to Python, but
> the PHP generation seems to have serious problems with C++ methods with
> default parameters:
>
> First problem: if I don't use "-noproxy" I get multiple definitions at
> runtime:
>
> Warning: Function registration failed - duplicate name - test in Unknown
> on line 0
>
> (These stem from identical lines in the _wrap.cpp file.)
>
> Second problem: if I do use "-noproxy," the resulting code appears to be
> valid, but frequently functions with default parameters simply don't get
> called. (It doesn't matter whether or not the default parameters are
> specified from PHP.)
>
> This seems most pronounced on methods containing a std::string parameter:
>
> ==== C++ Header:
> class MyTest {
>   public:
>     void Test(const std::string &st, bool b = false);
> };
>
> ==== C++ Source:
> void MyTest::Test(const std::string &st, bool b) {
>   std::cout << "This will never happen: " << st << std::endl;
> }
>
> ==== PHP Code:
> $mytest = new_Mytest();
> MyTest_Test($mytest,"Hi!");
>
> ==== SWIG file:
> %module mytest
> %include "std_string.i"
> %{
> #include "my_test.h"
> %}
> %include "my_test.h"
>
> In the above example, the body of MyTest::Test will never be called.  If
> I change the Test method, either of these will work fine:
>
> void Test(const std::string &st, bool b);  // No default value for b.
> void Test(int st, bool b=false); // Not a std::string anymore.
>
> And all of it works fine in Python.  Am I missing something about using
> std::string in this context that I could fix to at least get it working
> with -noproxy for PHP?
>
> Thanks for any advice!  SWIG seems like a fantastic tool.
>
> Jeff
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Swig-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/swig-user
>  



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|

Re: Generate C wrappers from C++?

swig
In reply to this post by Marcelo Matus

What non-OO languages does SWIG target?

Does it operate in any "no classes" mode for any of the OO targets?

Can you recommend an existing target to base the C target on?

> No, sorry, "C" is not a target language right now (as is
> tcl,python,java,csharp, etc, etc).
> But people keeps asking for the same, maybe one day we will have a
> volunteer to
> write a C target module.
>
> Marcelo
>
> [hidden email] wrote:
>
> >I kind of assumed I could do this, but it is not mentioned.
> >
> >Can I generate C wrappers of a C++ library with SWIG?
> >
> >  
> >

--
 kai



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|

Re: Generate C wrappers from C++?

Marcelo Matus
You probably would like to take a look at the Csharp module, because is
a non-scripting
language, and the Tcl module, which is a non-OO language.

The C module should look like a mix between them.

Marcelo


[hidden email] wrote:

>What non-OO languages does SWIG target?
>
>Does it operate in any "no classes" mode for any of the OO targets?
>
>Can you recommend an existing target to base the C target on?
>
>  
>
>>No, sorry, "C" is not a target language right now (as is
>>tcl,python,java,csharp, etc, etc).
>>But people keeps asking for the same, maybe one day we will have a
>>volunteer to
>>write a C target module.
>>
>>Marcelo
>>
>>[hidden email] wrote:
>>
>>    
>>
>>>I kind of assumed I could do this, but it is not mentioned.
>>>
>>>Can I generate C wrappers of a C++ library with SWIG?
>>>
>>>
>>>
>>>      
>>>
>
>  
>



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user