<div dir="ltr">Thanks for your input everyone. I got it working in a bare bones project. I am still having the original problem in my actual program which is using s7 as an extension language in the Cocos2d-x game engine, but now I am sure the problem lies with Cocos2d-x. It was ported from objective C to C++, so a lot of the pointer stuff is odd.<div><br></div><div>Here is the working sample C++ project in case it is of use to anyone:</div><div><br></div><div><div>//Scheme.h</div><div>#ifndef __SCHEME_H__</div><div>#define __SCHEME_H__</div><div><br></div><div>#include "s7.h"</div><div>#include "stdlib.h"</div><div><br></div><div>extern "C" {</div><div><br></div><div>class Scheme</div><div>{</div><div>public:</div><div> static s7_pointer plus(s7_scheme *sc, s7_pointer args);</div><div> Scheme();</div><div> ~Scheme();</div><div> int addFFItoScheme();</div><div> int testFFI();</div><div>private:</div><div> static s7_scheme* s7;</div><div>};</div><div>}</div><div>#endif</div></div><div><br></div><div><div>//Scheme.cpp</div><div>#include "s7.h"</div><div>#include "Scheme.h"</div><div>#include <stdlib.h></div><div>#include <iostream></div><div><br></div><div>s7_scheme* Scheme::s7;</div><div>s7_pointer Scheme::plus(s7_scheme *sc, s7_pointer args)</div><div>{</div><div> /* (define* (plus (red 32) blue) (+ (* 2 red) blue)) */</div><div> return(s7_make_integer(sc, 2 * s7_integer(s7_car(args)) + s7_integer(s7_car(s7_cdr(args)))));</div><div>}</div><div><br></div><div>Scheme::Scheme() {</div><div> s7 = s7_init();</div><div> std::cout << "Scheme init\n";</div><div>}</div><div><br></div><div>Scheme::~Scheme() {</div><div> free(s7);</div><div> std::cout << "Bye!\n";</div><div>}</div><div><br></div><div>int Scheme::addFFItoScheme()</div><div>{</div><div> std::cout << "addFFItoScheme\n";</div><div> s7_define_function_star(s7, "plus", Scheme::plus, "(red 32) blue", "an example of define* from C");</div><div> return 0;</div><div>}</div><div><br></div><div>int Scheme::testFFI()</div><div>{</div><div> std::cout << "testFFI\n";</div><div> auto val = s7_eval_c_string(s7, "(+ 2 3)"); // should be 5</div><div> std::cout << "5 = " << s7_object_to_c_string(s7, val) << std::endl;</div><div> val = s7_eval_c_string(s7, "(plus 2 3)"); // should be 7</div><div> std::cout << "7 = " << s7_object_to_c_string(s7, val) << std::endl;</div><div> return 0;</div><div>}</div></div><div><br></div><div><div>//main.cpp</div><div>#include "s7.h"</div><div>#include "Scheme.h"</div><div>#include "Scheme.cpp"</div><div><br></div><div>int main(int argc, char **argv)</div><div>{</div><div> std::cout << "Main" << std::endl;</div><div> Scheme* scheme = new Scheme();</div><div> scheme->addFFItoScheme();</div><div> scheme->testFFI();</div><div><br></div><div>}</div><div><br></div><div>//to build:</div><div>//g++ -c s7.c -I. -g</div><div>//g++ -c Scheme.cpp -I. -g -std=c++0x && g++ main.cpp -o ffi s7.o -I. -lm -ldl -std=c++0x && ./ffi</div></div><div><br></div><div>and output is as expected:</div><div><div>Main</div><div>Scheme init</div><div>addFFItoScheme</div><div>testFFI</div><div>5 = 5</div><div>7 = 7</div></div><div><br></div><div>Thanks again for your help,</div><div>Jason</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 12, 2015 at 10:39 AM, Ralf Mattes <span dir="ltr"><<a href="mailto:rm@seid-online.de" target="_blank">rm@seid-online.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Thu, Feb 12, 2015 at 10:42:31AM -0500, Jason Ripley wrote:<br>
<br>
</span><span class="">> should. However, I cannot seem to find the correct invocation in C++ to<br>
> make it work. I was wondering if it needs something like extern "C", which<br>
> I tried to no avail.<br>
<br>
</span>Yes, when compiling with a C++ compiler you need to declare your calls into<br>
C as "extern C" otherwise you'll be the victim of name mangling.<br>
<br>
Cheers, RalfD<br>
<br>
<br>
Yes, when compiling with a C++ compiler you need to declare your calls into<br>
C as "extern C" otherwise you'll be the victim of name mangling.<br>
<br>
Cheers, RalfD<br>
<br>
</blockquote></div><br></div>