Thanks guys that worked!!
On Friday, November 14, 2014 4:22:44 PM UTC-5, Luthaf wrote:
>
> The first way to compile is the good one, but gfortran is slightly
> changing the names of the function. You can see it by running the `nm`
> command :
> ```
> $ nm simplemodule.so
> 0000000000000f98 T ___simplemodule_MOD_foo
> ```
>
> So you have to call `__simplemodule_MOD_foo` from Julia side (yes, with
> one underscore less. I don't know why ...)
>
> ```
> julia> ccall((:__simplemodule_MOD_foo, "simplemodule.so"), Int32,
> (Int32,), 3)
> ```
>
> This will also lead to a segfault, as Fortran except values to be passed
> by reference, and not by value. So the final call is
>
> ```
> julia>ccall((:__simplemodule_MOD_foo, "simplemodule.so"), Int32,
> (Ptr{Int32},), &3)
> 6
> ```
>
> Regards,
> Guillaume
>
> Andre Bieler a écrit :
>
> 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)
>
>
> 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
>
>