On Fri, Nov 14, 2014 at 4:08 PM, Andre Bieler <[email protected]> wrote:
> tried calling a simple fortran function from julia but did not succeed:
> this is the fortran code:
>
> !fileName = simplemodule.f95
> module simpleModule
>
> contains
> function foo(x)
> integer :: foo, x
> foo = x * 2
> end function foo
>
>
> end module simplemodule
>
>
> which is then compiled with:
>
> gfortran simplemodule.f95 -o simplemodule.so -shared -fPIC
>
> and finally the julia call is:
>
>
> ccall((:foo, "/fullPathTo/simpleMod.so"), Int32, (Int32,), 3)
>
You have to mangle the function name because of the module, so
something like this might work:
a = Int32[3]
ccall(("__simplemodule_MOD_foo","./simplemodule.so"),Int32,(Ptr{Int32},),a)
-Mike
>
> which then leads to the following error:
>
> ERROR: ccall: could not find function foo in library
> /fullPathTo/simpleMod.so
> in anonymous at no file
>
>
>
> when compiling with:
>
> gfortran -c simplemodule.f95 -o simplemodule.so -shared -fPIC
>
> i get a different error:
>
> ERROR: error compiling anonymous: could not load module
> /fullPathTo/simplemodule.so: /fullPathTo/simplemodule.so:
> only ET_DYN and ET_EXEC can be loaded
>
>
>
> Can anyone tell me what I am missing?
> I do realize I would not need to call fortran to multiply a variable by 2,
> but its a starting point..
>
>
> Thanks!
> Andre