Valgrind
on Ubuntu i installed using
sudo apt-get install valgrind
sudo apt-get install valgrind
from ctypes import cdll
from ctypes import c_char_p
from ctypes import c_float
lib = cdll.LoadLibrary('libmylib.so')
helloWorld = lib.MYLIB_helloWorld
helloWorld()
install ffi. linux distros have packages.....so on ubuntu apt-get install ffi...
then here is the module code as well as sample script
module LibMylib
extend FFI::Library
ffi_lib "libmylib.so"
attach_function :MYLIB_helloWorld, [], :void
end
then your script. make sure libmylib is replaced with whatever u named the module file above
require 'ffi' require 'libmylib' LibMylib.MYLIB_helloWorld()
(defn helloworld ( []
( let [ lib ( com.sun.jna.NativeLibrary/getInstance "mylib" ) ]
( let [ helloWorld ( .getFunction lib "MYLIB_helloWorld" ) ]
( println ( .invokeVoid helloWorld null ) ) ) ) ) )
( helloworld )
then run with
java -cp /usr/share/java/clojure.jar:jna.jar:. -Djna.nosys=true clojure.main helloworld.clj
import com.sun.jna.*;
def lib = NativeLibrary.getInstance("mylib")
def helloWorld = lib.getFunction( "MYLIB_helloWorld" )
/*
if args do this
Object[] args = new Object[2];
args[0] = "arg1"
args[1] = "arg2"
*/
helloWorld.invokeVoid(null)
then run with
groovy -cp jna.jar:. -Djna.nosys=true helloworld.groovyfor more invoke options see http://jna.java.net/javadoc/com/sun/jna/Function.html
using System;
using System.Runtime.InteropServices;
public class HelloWorld
{
static public void Main( string[] args )
{
MYLIB_helloWorld();
}
[DllImport("libmylib.so")]
private static extern void MYLIB_helloWorld();
}
then run with
gmcs HelloWorld.cs mono HelloWorld.exe
import com.sun.jna.Library;
import com.sun.jna.Native;
interface MyLib extends Library {
MyLib INSTANCE = (MyLib) Native.loadLibrary("mylib", MyLib.class );
String MYLIB_helloWorld();
}
and a class that uses it
import com.sun.jna.Library;
import com.sun.jna.Native;
public class MyLibUser{
public static void main( String[] args ) {
MyLib lib = MyLib.INSTANCE;
lib.MYLIB_helloWorld();
}
}
now compile with
javac -cp jna.jar:. -Djna.nosys=true MyLibUserand run with
java -cp jna.jar:. -Djna.nosys=true MyLibUserGaaaangsta! No?