Maybe I'll need to switch to mingw64. On Cygwin, trying to compile issues a warning:
f951: warning: -fPIC ignored for target (all code is position independent) [enabled by default] That's for both ways of compiling: .so and dll. And I still get the dreaded error: ''error compiling anonymous: could not load module f90tojl... " I think CodeBlocks comes with mingw64 so I'll give that a try soon... Thanks, V. On Tuesday, December 16, 2014 11:27:41 PM UTC-5, Isaiah wrote: > > With the following changes, your example works for me on mingw64: > > "-o" needs to be paired with a filename: > > gfortran -shared -O2 f90tojl.f90 -fPIC -o f90tojl.dll > > This will allow your original ccall invocation to work. Julia doesn't look > at ".so" files by default on windows, but the following pair will also > work; the shared library extension is given explicitly in the ccall: > > gfortran -shared -O2 f90tojl.f90 -fPIC -o f90tojl.so > julia> ccall( (:__m_MOD_five, "f90tojl.so"), Int, () ) > > Hope this helps to get started. I agree that it would be great to have a > working Fortran example -- if you have a suggested example (or even this > one) please consider making a pull request (see > https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md). > > > On Tue, Dec 16, 2014 at 9:04 PM, Vathy M. Kamulete <[email protected] > <javascript:>> wrote: > >> I posted this on StackOverflow. It was recommended I post here. See here >> <http://stackoverflow.com/q/27498755/1965432>for background. >> >> Where can I find good examples of integrating (modern) Fortran code with >> Julia? >> >> I am using the GNU gfortran compiler (on Cygwin) for my own module. A >> good example will hopefully start from the compilation stage, address >> mangled names and call the subroutine from Julia via ccall. Most examples >> I've seen skip the first two stages. On the SO post, I refer to Modern >> Fortran explicitly because what I've seen so far tends to be for legacy >> code -- think punchcard-style fixed-width formatting Fortran (that goes for >> GLMNet, which was allegedly written in 2008 but adheres to those >> conventions). >> >> So imagine that I have the following module in Fortran90 file named >> 'f90tojl.f90': >> >> module m >> contains >> integer function five() >> five = 5 >> end function five >> end module m >> >> This example is from here >> <http://en.wikipedia.org/wiki/Name_mangling#Name_mangling_in_Fortran>. I >> compile it with gfortan as follows to create a shared library: >> >> gfortran -shared -O2 f90tojl.f90 -o -fPIC f90tojl.so >> >> And my, admittedly shaky, understanding from reading the julia docs >> suggest that I should be able to call the function five like so: >> >> ccall( (:__m_MOD_five, "f90tojl"), Int, () ) >> >> It didn't work for me. I get ''error compiling anonymous: could not load >> module f90tojl... ". Anyone cares to enlighten me? I got the sneaky sense >> I'm doing something silly.... >> >> Thanks in advance, >> >> V. >> > >
