From: Erik Toussaint on
On 7-7-2010 9:16, Uno wrote:
> ! gfortran -Wall -Wextra f_pi2.f90 -o fortranlib.o
> $
>
> How do I tell gfortran.exe not to expect main?

Instruct it to just compile, don't link by using the -c switch:

gfortran -c -Wall -Wextra f_pi2.f90 -o fortranlib.o

Erik.
From: m_b_metcalf on
On Jul 7, 6:29 am, Uno <merrilljen...(a)q.com> wrote:
>
> q2) If this calculation is done in a posix-compliant environment, are
> the widths of C's double and fortran's default real related?
>

Does the Table 14.1 in MR&C, p. 250, provide you with the
information you're looking for?

>
> q3)  Why does the MR&C development need the interface listed in figure
> 14.3 *and* the interface lsited in 14.4?
>
Fig. 14.3 is related to Fortran calling C. It's 14.4 you want.

HTH,

Mike Metcalf
From: Uno on
Erik Toussaint wrote:
> On 7-7-2010 9:16, Uno wrote:
>> ! gfortran -Wall -Wextra f_pi2.f90 -o fortranlib.o
>> $
>>
>> How do I tell gfortran.exe not to expect main?
>
> Instruct it to just compile, don't link by using the -c switch:
>
> gfortran -c -Wall -Wextra f_pi2.f90 -o fortranlib.o

Thx, Erik. Sometimes I get hung up on super easy things.

Now, the linker is complaining about not finding atan. If it were C, I
would think to include math.h, but that's not relevant here. I tried
adding -D_GNU_SOURCE to no avail, so I'm stuck again :-(

$ gfortran -c -D_GNU_SOURCE -Wall -Wextra f_pi2.f90 -o fortranlib.o
$ gcc fortranlib.o -std=c99 -Wall -Wextra c_pi2.c -o out
fortranlib.o: In function `myArctan':
f_pi2.f90:(.text+0x19): undefined reference to `atan'
collect2: ld returned 1 exit status
$ cat c_pi2.c


#include <stdio.h>
#include <math.h>

double myArctan (double);

// C will be caller

int main()
{

double d;
double x = 1.0;
d = atan(1.0);
printf("d in C is %f\n", d);
printf("myarctan(%e) = %e\n", x, myArctan(x));

return 0;
}

// gcc fortranlib.o -std=c99 -Wall -Wextra c_pi2.c -o out
$ cat f_pi2.f90
function myarctan(x) bind(C,name='myArctan')
use iso_c_binding
implicit none
real(c_double), VALUE, intent(in) :: x
real(c_double) :: myarctan
myarctan = atan(x)
end function myarctan

! gfortran -c -D_GNU_SOURCE -Wall -Wextra f_pi2.f90 -o fortranlib.o
$

Fishing for tips,
--
Uno
From: Erik Toussaint on
On 7-7-2010 23:53, Uno wrote:
> Now, the linker is complaining about not finding atan. If it were C, I
> would think to include math.h, but that's not relevant here. I tried
> adding -D_GNU_SOURCE to no avail, so I'm stuck again :-(
>
> $ gfortran -c -D_GNU_SOURCE -Wall -Wextra f_pi2.f90 -o fortranlib.o
> $ gcc fortranlib.o -std=c99 -Wall -Wextra c_pi2.c -o out
> fortranlib.o: In function `myArctan':
> f_pi2.f90:(.text+0x19): undefined reference to `atan'
> collect2: ld returned 1 exit status

I think this happens because you invoke the linker as gcc. When invoked
as gfortran it automatically includes the fortran libraries, which
contain the code for the intrinsic functions.

Erik.
From: user1 on
Uno wrote:

> Now, the linker is complaining about not finding atan. If it were C, I would think to include math.h, but that's not relevant here. I tried adding -D_GNU_SOURCE to no avail, so I'm stuck again :-(


gfortran -c f_pi2.f90 -o fortranlib.o
gcc -c c_pi2.c
gfortran c_pi2.o fortranlib.o -o out




First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: non printing characters
Next: Fortran problem