public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Problem to call a Fortran subroutine in C++
@ 2006-09-13  2:50 Americo Barbosa da Cunha Junior
  2006-09-13 12:12 ` Tim Prince
  0 siblings, 1 reply; 2+ messages in thread
From: Americo Barbosa da Cunha Junior @ 2006-09-13  2:50 UTC (permalink / raw)
  To: gcc-help

I've trying to call a Fortran subroutine in a C++ code.

Below you can see the declaration of the subroutine and the part of C++ 
code that call it.


extern "C" {
extern void F_(int *n, double *tn, double *y, double *ftem, double 
*rpar, int *ipar);
}

// Jacobian
void jacobian(double **Jac, double *savf, double *y, double dt, int n)
{
    int i,j;
    double *ftem = malloc_vector(n);       // Vetor com Reaction Mapping 
Perturbado  
    double *rpar = malloc_vector(n);       // Vetor de trabalho double
    int    *ipar = malloc_ivector(n);          // Vetor de trabalho inteiro
    double *EWT = vector_ewt(y,n);      // Error Weight Vector
    double u = uround();                         // Roundoff
    double R, R0, FAC, tn;
  
    FAC = vector_wnorm(savf,EWT,n);
    R0 = 1000*fabs(dt)*u*FAC*(double)n;
    if( R0 == 0.0)
        R0 = 1.0;
 
    for(i = 0; i < n; i++)
    {
        R = max(sqrt(u)*fabs(y[i]),R0/EWT[i]);      // Perturbação
        y[i] += R;                                                    // 
Perturbando o vetor composicao
        F_(&n,&tn,y,ftem,rpar,ipar);                      // Preenche o 
ftem com o Reaction Mapping perturbado
        FAC = 1.0/R;
        for(j = 0; j < n; j++)
            Jac[i][j] = (ftem[j]-savf[j])*FAC;
    } 
}


Whem I try to link both languages the compiler returns the following 
error message: undefined reference to 'F_'

I did all procedures described in : 
http://www.physics.utah.edu/~detar/phycs6720/handouts/fortran_binding.html

Anybody can help me?

Thanks.

Americo Junior

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Problem to call a Fortran subroutine in C++
  2006-09-13  2:50 Problem to call a Fortran subroutine in C++ Americo Barbosa da Cunha Junior
@ 2006-09-13 12:12 ` Tim Prince
  0 siblings, 0 replies; 2+ messages in thread
From: Tim Prince @ 2006-09-13 12:12 UTC (permalink / raw)
  To: Americo Barbosa da Cunha Junior; +Cc: gcc-help

Americo Barbosa da Cunha Junior wrote:
> I've trying to call a Fortran subroutine in a C++ code.
> 
> Below you can see the declaration of the subroutine and the part of C++ 
> code that call it.
> 
> 
> extern "C" {
> extern void F_(int *n, double *tn, double *y, double *ftem, double 
> *rpar, int *ipar);
> }
> 
> // Jacobian
> void jacobian(double **Jac, double *savf, double *y, double dt, int n)
> {
>    int i,j;
>    double *ftem = malloc_vector(n);       // Vetor com Reaction Mapping 
> Perturbado     double *rpar = malloc_vector(n);       // Vetor de 
> trabalho double
>    int    *ipar = malloc_ivector(n);          // Vetor de trabalho inteiro
>    double *EWT = vector_ewt(y,n);      // Error Weight Vector
>    double u = uround();                         // Roundoff
>    double R, R0, FAC, tn;
>  
>    FAC = vector_wnorm(savf,EWT,n);
>    R0 = 1000*fabs(dt)*u*FAC*(double)n;
>    if( R0 == 0.0)
>        R0 = 1.0;
> 
>    for(i = 0; i < n; i++)
>    {
>        R = max(sqrt(u)*fabs(y[i]),R0/EWT[i]);      // Perturba??o
>        y[i] += R;                                                    // 
> Perturbando o vetor composicao
>        F_(&n,&tn,y,ftem,rpar,ipar);                      // Preenche o 
> ftem com o Reaction Mapping perturbado
>        FAC = 1.0/R;
>        for(j = 0; j < n; j++)
>            Jac[i][j] = (ftem[j]-savf[j])*FAC;
>    } }
> 
> 
> Whem I try to link both languages the compiler returns the following 
> error message: undefined reference to 'F_'
> 
> I did all procedures described in : 
> http://www.physics.utah.edu/~detar/phycs6720/handouts/fortran_binding.html
> 
Did you notice they used lower case names?  A pity they didn't advice 
you to run nm or the like on the individual .o files to help you resolve 
any such discrepancies.  Fortran compilers, by default, collapse the 
linkage names to all lower (in the case of GNU fortran) or all upper case.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-09-13 12:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-13  2:50 Problem to call a Fortran subroutine in C++ Americo Barbosa da Cunha Junior
2006-09-13 12:12 ` Tim Prince

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).