call C++ function from newlisp code

Q&A's, tips, howto's
Locked
csfreebird
Posts: 107
Joined: Tue Jan 15, 2013 11:54 am
Location: China, Beijing
Contact:

call C++ function from newlisp code

Post by csfreebird »

Is it possible to call a c++ function, I want to build a C++ so file which has some functions for accessing database, then write a newlisp app to use it. I am working on Ubuntu.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: call C++ function from newlisp code

Post by Lutz »

In your C++ programs you have to declare functions as extern "C". Then they can be imported into newLISP using either the simple or extended import interface.

Windows DLL:

Code: Select all

extern "C" __declspec( dllexport ) int MyFunc(int a, int b);
or on other OS:

Code: Select all

extern "C" int MyFunc(int a, int b);

csfreebird
Posts: 107
Joined: Tue Jan 15, 2013 11:54 am
Location: China, Beijing
Contact:

Re: call C++ function from newlisp code

Post by csfreebird »

I made an example, see my blog
http://csfreebird.blogspot.com/2013/12/ ... namic.html

Thank you, Lutz.

Locked