3

I would like to use some routines of the DIERCKX library (which is written in Fortran) in a program written in FreePascal with Lazarus. Since I'm totally new to Lazarus, I'd like to know which way to go: Which steps are necessary, and how do I go about this?

EDIT Developing on Linux, but the library I create will need to be compiled on Windows, because it will be used in a Delphi program. gfortran and g95 are installed on my Linux box; but it would be good to be able to compile it on Windows without Cygwin and without Intel Fortran.

andreas-h
  • 10,679
  • 18
  • 60
  • 78
  • 2
    You should be able to call FORTRAN subroutines from FreePascal, just as you can call C: http://lists.freepascal.org/lists/fpc-pascal/2009-January/019917.html Q: Are you on Linux? Q: Are you using gfortran? – paulsm4 Feb 23 '12 at 17:13
  • @paulsm4 edited question to answer your remarks. Windows. No-Cygwin, no-ifort. – andreas-h Feb 24 '12 at 17:04

1 Answers1

3

I think you are overcomplicating the situation here.

Lazarus is not equal to Delphi.

  • Delphi can't access Free Pascal constructs beyond the base procedural level. (the C compatible part). If your idea is to abstract the GNU world with FPC and then call that from Delphi, that will fail.
  • Delphi can't link statically to gcc libraries. To access gcc originating code, you will have to turn it into a DLL, and load that from Delphi.
  • FPC can link statically to gcc libraries (cygwin, mingw), but can only call plain procedures/functions without mangling or language specific types.
  • FPC can of course also use gcc originating code in DLLs.
  • As for approach Fortran code from FPC, prepare it if it needs to be called from C, make sure it works, then convert the relevant headers to Pascal with the CDECL calling convention (see the FPC sourcecode repo for many examples of translated C headers)

For the rest it would be clearer if you explain where exactly you are stuck.

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89