External Functions and Compiler linking issues

This is a discussion on External Functions and Compiler linking issues within the C Programming forums, part of the General Programming Boards category; Hey, Ok here goes... I needed to separate a function (mmult) I had made from the driver program so I ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    17

    External Functions and Compiler linking issues

    Hey,

    Ok here goes...
    I needed to separate a function (mmult) I had made from the driver program so I put it in its own .c file. The C driver though calls mmult.c and other Fortran functions so i needed to compile it using the fortran compiler. The mmult function uses OpenMp directives and so I need to use the intel compiler with the -openmp switch to take advantage, as g77 doesn't seem to support openMP.

    Ok...

    I can compile ok with without openMp support
    >f77 -o mm mm.c mmult.c dgemm.o xerbla.o lsame.o
    but when I try to use the fortran compiler (with or without omp)...
    >ifort -openmp -o mm mm.c mmult.c dgemm.o xerbla.o lsame.o
    I get ...
    mm.c: file not recognized: File format not recognized
    I think it's because it wants the object file.

    This is where my problem comes in...
    - I can't compile the mm.c file on it's own because it needs the fortran functions.
    - I can't compile the mmult.c as it hasn't got a main i think:
    /usr/lib/crt1.o(.text+0x18): In function `_start':
    ../sysdeps/i386/elf/start.S:115: undefined reference to `main'
    Any ideas what i'm supposed to do here?

    Thanks,

    Colly

    Oh - has anyone got any idea where I can get help with modifying my matrix multiplier (based on DGEMM) to work with OpenMP?

    Thanks.

  2. #2
    Registered User
    Join Date
    Apr 2005
    Posts
    10
    I can be 110% wrong, but I thought you can do object even without main???

    And, how about compiling the fortran functions first?

    And generally, if you solve the problem, I am EXTREMELY interested in hearing how you do combine the languages, as I know C/C++ much better than fortran, but I do need fortran at times to do some maths...

    mm.. f77? Fortran 77? Have you tried with f90 or f95 (fortran 90/95)? (again, I do not know what I am talking about, I haven't done that myself.)

    EDIT:
    I tried searching answers from my materials, and only comments I found out about openMP, were related to f95 and mmm.. whatchamacallit.. "dual programming" (I don't know the english term) O_o

    EDIT2:
    I bet you knew this already, but... Well, check it iut yourself
    http://owen.sj.ca.us/rkowen/howto/Fa....call.html#f2c
    Last edited by Guest852; 04-07-2005 at 04:32 PM.
    10 ?"Do you want to know a good site?"
    20 Get a$
    30 IF a$ == "" THEN GOTO 20
    40 IF a$ == "y" THEN GOTO 70
    50 IF a$ == "n" THEN GOSUB 20000
    60 sys 64738
    70 GOTO <insert your fav site here>
    80 END
    20000 ?"Then I cant see why you use computer. So blind shall be you too"
    20010 FOR I = 1 to 10000
    20020 NEXT I
    20030 poke 53265,11
    20040 END
    Does this make sence?

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    17
    I am EXTREMELY interested in hearing how you do combine the languages, as I know C/C++ much better than fortran, but I do need fortran at times to do some maths...
    Like I said they can be linked fine. It's just with the intel compiler that I can't get it to compile. f77 and g77 work fine
    >f77 -o mm mm.c mmult.c dgemm.o xerbla.o lsame.o
    compiles just file.

    how about compiling the fortran functions first?
    Yeah I had actually compiled them all separately, but can you tell me how do the linking of all the files using the C compiler instead of the Fortran compiler - I was doing it the fortran way because apparently "...the fortran compiler knows where the C libraries are but the C compiler has to be told where the fortran libraries are...". And to be honest with you my compiler doesn't listen to me much anyway.

    If its possible to compile a C file without a main then there must be something wrong with my code... or do i need to use a compiler arg?

    Code:
    //mmult.c
    #include <stdlib.h>
    #include <stdio.h>
    #ifdef _OPENMP
    #include <omp.h>
    #endif /* OPENMP */
    
    typedef enum
    {
      FALSE,
      TRUE
    } boolean;
    
    int mmult_(char *transA, char *transB, int *m_rows, int *n_cols, int *k_common, double *alpha, double *matrixA, int *lda, double *matrixB, int *ldb, double *beta, double *matrixC, int *ldc);
    
    int mmult_(char *transA, char *transB, int *m_rows, int *n_cols, int *k_common, double *alpha, double *matrixA, int *lda, double *matrixB, int *ldb, double *beta, double *matrixC, int *ldc)
    {...
    }
    Code:
    //mm.c (driver)
    ...
    extern int mmult_(char *transA, char *transB, int *m_rows, int *n_cols, int *k_common, double *alpha, double *matrixA, int *lda, double *matrixB, int *ldb, double *beta, double *matrixC, int *ldc);
    ...
    That's ok isn't it??

    Thanks,

    Colly

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [C] Compiler error while using functions
    By Scupham in forum C Programming
    Replies: 7
    Last Post: 12-09-2008, 06:25 PM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. Problem with OpenGL tutorial
    By 2Biaz in forum Windows Programming
    Replies: 18
    Last Post: 09-16-2004, 12:02 PM
  4. Replies: 3
    Last Post: 11-03-2003, 04:43 PM
  5. error LNK2001: unresolved external symbol
    By Unregistered in forum C Programming
    Replies: 12
    Last Post: 07-12-2002, 09:45 PM

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