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 scriptmodule LibMylib extend FFI::Library ffi_lib "libmylib.so" attach_function :MYLIB_helloWorld, [], :void endthen 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?
So if you need some raw of performance in your application what do you do? You drop down into a native development language like C. Well what if you want to code with OOP goodness and use C++. Regular calls from Java, Ruby, etc. will not get to your C++ functions because C++ adds all sorts of template madness when it exports your programs symbols.
So what do you do?
extern "C"so if your want to wrap your c++ classes in a single method called helloWorld (or MYLIB_helloWorld to not be confused with other helloWorlds!):
extern "C" MYLIB_helloWorld();in your header file.....then in your cpp file you can just do the normal
MYLIB_helloWorld();Yay! Now you can make native calls from higher level languages like java or even ruby without them getting pissed off at the c++ template symbols. Will post examples soon.
ssh-host-config -ywhen prompted with the CYGWIN=
tty ntsecand then finally
cygrunsrv -S sshdYou might hit ERRORS wither on first start or 2 years later! Most common that I've run into are:
passwd cyg_serverin your cygwin shell to change it ... For the second problem just repeat the steps from STEP one to reconfigure.. Cheers!