Thread: mixed program c/fortran

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    133
    Try "-L/opt/intel/fc/9.0/lib/" switch to tell compiler where libraries are, specify it before -lifcore. If that won't work, maybe library is not 32-bit.

  2. #2
    Registered User
    Join Date
    Aug 2008
    Location
    London and Lyon
    Posts
    26
    Thanks to all of you. You helped me a lot with these very annoying programming problems.

    Now it is working. To summarize I compile with

    ifort -c tn.f
    ifort -c blas.f
    gcc -m32 -g -c test1.c
    gcc -g -m32 test1.o tn.o blas.o -L/opt/intel/fc/9.0/lib/ -lifcore -lg2c


    and to pass in a function another fortran function as argument one as to write someting like that

    Code:
    #include <stdlib.h>
    #include <math.h>
    
    void SFUN(int *N, double *X, double *F, double *G)
    {
    int i;
    double T;
    *F=0.0;
    for (i = 0 ; i < *N ; i++)
        {
        T = 2*X[i] - i;
        *F = *F +T*T;
        G[i] = 2.0 * T;
        }
    }
    
    int main(void)
    {
    int N=200;
    double F=-1000.0;
    double G[300],X[300];
    
    extern void pseudolmqn_(int *N, double X[], double *F, double G[], void (*SFUN)(int *N, double X[], double *F, double G[]));
    
    
    printf("F before test is %lf\n",&F);
    
    pseudolmqn_(&N, X, &F, G, SFUN);
    
    printf("F after test is %lf\n",&F);
    
    }
    where pseudolmqn.f is

    Code:
          SUBROUTINE pseudolmqn(N, X, F, G, SFUN)
          IMPLICIT          NONE
          INTEGER N
          DOUBLE PRECISION  X(N), G(N), F, FNEW
          EXTERNAL SFUN
    
          CALL SFUN(N,X,FNEW,G)
          F=FNEW+1.0
    
          RETURN
          END
    AND THIS WORKS !!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM