mixed program c/fortran

This is a discussion on mixed program c/fortran within the C Programming forums, part of the General Programming Boards category; So, you probably should not use upper-case in your filename. Fortran is not case-sensitive, so the compiler will convert all ...

  1. #31
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, you probably should not use upper-case in your filename. Fortran is not case-sensitive, so the compiler will convert all names to same case, in this case lowercase, so that the linker doesn't have to know if the language cares about case or not - it just matches the name in the object file.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #32
    Registered User
    Join Date
    Aug 2008
    Location
    London and Lyon
    Posts
    26
    WHAOOU

    It compiled, I see what you mean I put everywhere pseudolmqn in the c code and it works !!!

    Thanks, what a relief. Let's not get carried away though.

  3. #33
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by mimi1981 View Post
    WHAOOU

    It compiled, I see what you mean I put everywhere pseudolmqn in the c code and it works !!!

    Thanks, what a relief. Let's not get carried away though.
    Now, the next question is if your mixed code produces correct results!

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #34
    Registered User
    Join Date
    Aug 2008
    Location
    London and Lyon
    Posts
    26
    Hi again

    We did one little step but there are still quite a few I suspect.

    Now I pass to the actual code and I do

    gcc -c -m32 test1.c
    ifort -c tn.f
    ifort -c blas.f
    gcc -m32 test1.o tn.o blas.o -lm

    and I get the errors related to the linking to the libraries

    tn.o(.text+0x136): In function `tn_':
    : undefined reference to `for_write_seq_fmt'
    tn.o(.text+0x16d): In function `tn_':
    : undefined reference to `for_write_seq_fmt'
    tn.o(.text+0x1a1): In function `tn_':
    : undefined reference to `for_write_seq_fmt'
    tn.o(.text+0x1d7): In function `tn_':
    : undefined reference to `for_write_seq_fmt'
    tn.o(.text+0x204): In function `tn_':
    : undefined reference to `for_write_seq_fmt_xmit'
    tn.o(.text+0x226): In function `tn_':
    : undefined reference to `for_write_seq_fmt_xmit'
    tn.o(.text+0x241): In function `tn_':
    : undefined reference to `for_write_seq_fmt_xmit'
    tn.o(.text+0x2bd): In function `lmqn_.':
    : undefined reference to `for_write_seq_fmt'
    tn.o(.text+0x48a): In function `lmqn_.':
    : undefined reference to `for_write_seq_fmt'
    tn.o(.text+0x4b2): In function `lmqn_.':
    : undefined reference to `for_write_seq_fmt_xmit'
    tn.o(.text+0x4da): In function `lmqn_.':
    : undefined reference to `for_write_seq_fmt_xmit'
    tn.o(.text+0x502): In function `lmqn_.':

    etc....etc....


    I saw on a forum someone with a similar problem got reed of these undefined... by typing -lifcore, but strangely while I can see the library associated to this command in /opt/intel/fc/9.0/lib/ it is libifcore.a the command doesn't work it gives


    gcc -m32 test1.o tn.o blas.o -lm -lifcore

    /usr/bin/ld: ne peut trouver -lifcore (means cannot find -lifcore ?????????)
    collect2: ld a retourné 1 code d'état d'exécution


    What doesn't it work ???

    IDEAS ???

    Thanks a lot, one day it will work !!

  5. #35
    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.

  6. #36
    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 !!!!

  7. #37
    Registered User
    Join Date
    Aug 2008
    Location
    London and Lyon
    Posts
    26
    Hi all!

    The problem is now a little bit different.

    I am compiling with

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

    and it works fine

    BUT now I want to replace the test code test1.c by my own code test1_KANT.c but this new code requires the library -lgsl -lgslcblas, so I try

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

    and it gives me

    /usr/bin/ld: escamotage incompatible /usr/lib64/libgsl.so lors de la recherche de -lgsl
    /usr/bin/ld: escamotage incompatible /usr/lib64/libgsl.a lors de la recherche de -lgsl
    /usr/bin/ld: ne peut trouver -lgsl
    collect2: ld a retourn 1 code d'tat d'excution

    It seems that -lgsl -lgslcblas are configured to go and look in /usr/lib64/ while I suspect they should in this case look in /usr/lib/

    But in
    /usr/lib64/ I found

    libgslcblas.a
    libgslcblas.la
    libgslcblas.so
    libgslcblas.so.0
    libgslcblas.so.0.0.0

    and in /usr/lib/ only
    libgslcblas.la
    libgslcblas.so.0
    libgslcblas.so.0.0.0
    libgsl.la
    libgsl.so.0
    libgsl.so.0.6.0

    so not the libgsl.a ???

    Why can't I compile everything in 64 bits , how can I link the new code with the gsl libraries ??

    PLEASE HELP
    THANKS A LOT

  8. #38
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You probably could compile everything 64-bit if you compile it with g77 - the gcc version of Fortran77. If you want to use ifort, it probably also exists in a 64-bit version.

    If you can't change the compiler, you probably need to install some 32-bit "-devel" components to get the 32-bit version of those libraries.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #39
    Registered User
    Join Date
    Aug 2008
    Location
    London and Lyon
    Posts
    26
    Great this forum is really fantastic and Matsp in particular !!! Thanks, your advices are always spot on.

    I did as you suggested

    gcc -c test1_KANT.c
    g77 -c tn.f
    g77 -c blas.f
    gcc test1_KANT.o tn.o blas.o -lgsl -lgslcblas -lg2c

    -lg2c is crucial, don't ask me why.

    and IT WORKS

  10. #40
    Registered User
    Join Date
    Jun 2005
    Posts
    5,843
    g2c is GNU's Fortran run time library. g77, when it compilers Fortran code, converts a number of operations (aka language features) into calls of functions in the run time library. It's also possible (I haven't specifically checked) the other libraries you are using (gsl, gslcblas) also make use of the Fortran run time library. Either way, -lg2c would be required.

Page 3 of 3 FirstFirst 123
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, 12: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, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21