This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: linking windows dll with cygwin gcc


This is just the solution to my request for anybody who is interested
to link cygwin-gcc with lahey lf95 under windows. The following
set of commands is required

lf95 -win -dll -ml msvc demofact.f90 -c
lf95 demofact.obj -dll
dlltool -U --def demofact.def --dllname demofact.dll --output-lib demofact.a

gcc f95_dll2.c demofact.a

demofact.f90, f95_dll2.c and demofact.def are

%%%%%%%%
demofact.f90:
        !!  subroutine : FACTORIAL_DEMO taken from Lahey examples
        !!
        !!      sets up the factorial demonstration and governs the
        !!      invocation of 'factorial'
        !!
        subroutine factorial_demo(factorials, count)
            dll_export factorial_demo
            integer count
            integer, dimension(count) :: factorials
            integer * 4 i,factorial
            i = 1
            do while (i <= count)
                factorials(i) = factorial(i)
                i = i + 1
            enddo
        end


        recursive function factorial(n) result(factresult)
            integer * 4  n,factresult
            if (n .eq. 1) then
                factresult = 1
            else
                factresult = n * factorial(n - 1)
            endif
        end

%%%%%%%
f95_dll2.c: modified from Lahey examples
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
#include <string.h>
#include <signal.h>
#include <limits.h>
#include <errno.h>
#include <math.h>
#include <time.h>
#include <float.h>
#include <windows.h>

HANDLE _stdin_handle;
HANDLE _stdout_handle;
HANDLE _stderr_handle;

/*
** Prototypes used locally.
*/
void ChooseFactorial(void);
/*
int WINAPI WinMain(HANDLE hInstance, HANDLE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
*/
int main()
{
    printf("debut");
    ChooseFactorial();
    return 0;
}

/*************************************************************************
**  This is how to define prototype for a Fortran Subroutine.
**
*************************************************************************/
/* void __stdcall factorial_demo(long *, long *); */
void __stdcall factorial_demo(long *, long *);

void ChooseFactorial()
{
#define number_of_factorials 12
    long num_of_factorials = number_of_factorials;
 long factorials[number_of_factorials];
 char buffer[81];

    /* Note that both arguments are passed by reference, the '&' is only
    ** required on the scalar.
    */
 factorial_demo(factorials, &num_of_factorials);
 printf("%d %d %d %d %d %d\n", factorials[0], factorials[1], factorials[2],
\
    factorials[3], factorials[4], factorials[5]);

}

%%%%%%%%
demofact.def:
EXPORTS
factorial_demo@8


Jean-Luc





Jean-Luc Vay wrote:

> I have already sent the following message and got no answer. Am I on
> the wrong discussion list?
>
> I am trying to compile a code running under UNIX on a NT platform.
> The core subroutine are written in FORTRAN90 with C interfaces to
> communicate with the language PYTHON. The graphics under PYTHON
> use the library GIST form the Yorick package. I was able to recompile
> Yorick and Python using cygwin-gcc and the X11 library. The problems
> come when I want to link my FORTRAN objects (compiled with
> Lahey LF95) with the C files compiled with gcc. The FORTRAN objects
> required some .lib libraries not compatible with gcc and the C objects
> need some .a libraries incompatible with lf95. I tried to go around that
> by building .dll libraries.
> I tried to link c files with gcc importing dll libraries created
> with lf95 or with BorlandC++ but when I tried the resulting executable,
> I got the error message "The procedure entry point myprocedure could
> not be located in the dynamic library mydll.dll".
> Does someone have an idea of what the problem is or eventually any
> suggestion of solving the problem in a different way?
> Jean-Luc
>
> --
> Want to unsubscribe from this list?
> Send a message to cygwin-unsubscribe@sourceware.cygnus.com

--
-------------------------------------------------
Jean-Luc Vay
Accelerator and Fusion Research Division
Lawrence Berkeley National Laboratory - MS 71J
Berkeley, CA 94720, USA
Tel: (1) 510-486-4934
Fax: (1) 510-495-2323
Email: jlvay@lbl.gov
-------------------------------------------------



--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]