Nп/п : 73 из 100
 От   : pehache                             2:5075/128        06 сен 23 23:35:20
 К    : db                                                    06 сен 23 00:37:03
 Тема : Re: Calling a C++ function from Forttran
----------------------------------------------------------------------------------
                                                                                 
@MSGID: <kls9koF4ootU1@mid.individual.net>
0376bb2b
@REPLY: 1@dont-email.me> ef8c0300
@REPLYADDR pehache <pehache.7@gmail.com>
@REPLYTO 2:5075/128 pehache
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID:
<kls9koF4ootU1@mid.individual.net>
@RFC-References: 1@dont-email.me>
<klobumFfoflU1@mid.individual.net> 1@dont-email.me>
@TZUTC: 0200
@PID: Mozilla/5.0 (Macintosh; Intel Mac OS X
10.13; rv:91.0) Gecko/20100101 Thunderbird/91.11.0
@TID: FIDOGATE-5.12-ge4e8b94
Le 06/09/2023 ? 14:24, db a ?crit :
> On 05.09.2023 11.50, pehache wrote:
>> Le 04/09/2023 ? 16:43, db a ?crit :
>>> I see that rather than try to convert a C++ function to
>>> Fortran, it might be better to call it from a Fortran
>>> program. So I found a description of how to do it

> It resulted in a Forytran program that calls a Fortran function
> that calls the C++ function IBAND (exists as iband.cpp). Here is
> the code (sorry for the length)

> module STUFF
>    integer, parameter :: dbl=selected_real_kind(14)
>    integer, parameter :: qud=selected_real_kind(30)
> end module STUFF
> program JBAND_TEST
>    use STUFF;   implicit none

>    real(dbl) :: curr, FORTJBAND
>    real(qud) :: tbar
>    do
>       read *, tbar
>       if (tbar < 0) exit
>       curr = FORTJBAND (tbar)
>       print `(" curr =", f10.4)`, curr
>    enddo
> end program JBAND_TEST
> function FORTJBAND (tbar)
>    use STUFF;   implicit none
>    interface
>      function JBAND (tbar) bind(c)
>      import JBAND, c_long_double
>      import tbar, c_long_double
>      end function JBAND
>    end interface
>    real(dbl) :: FORTJBAND
>    real(qud) :: tbar, JBAND
>    FORTJBAND = JBAND (tbar)
> end function FORTJBAND

1) You are missing the ISO_C_BINDING module
2) I don`t get the syntax with the "import"
3) you don`t need to declare JBAND in addition to the interface

=======================================
function FORTJBAND (tbar)
    use ISO_C_BINDING
    use STUFF
    implicit none
    interface
      function JBAND (tbar) bind(c)
        real(c_lonf_double) :: JBAND
        real(c_lonf_double) :: tbar
      end function JBAND
    end interface
    real(dbl) :: FORTJBAND
    real(qud) :: tbar
    FORTJBAND = JBAND (tbar)
end function FORTJBAND
=======================================


> I then wrote a script for running it, reproducing what the link
> tells me:

> cpp -o jband.o jband.cpp
> gfortran -o jbandtest.o jbandtest.f90
> gfortran jband.o jbandtest.o
> ./a.out << eoi
> 1.0
> 10.0
> -1
> eoi

> When I run this, I get this:

> ~/ownlib90/tests> ./jbandtest
> cpp: fatal error: cannot execute `cc1plus`: execvp: No such file or 
> directory
> compilation terminated.

Isn`t "cpp" just the C/C++ preprocessor? Shouldn`t you use "g++" instead?

-- 
"...sois ouvert aux id?es des autres pour peu qu`elles aillent dans le
m?me sens que les tiennes.", ST sur fr.bio.medecine
ST passe le mur du ?on : <j3nn2hFmqj7U1@mid.individual.net>
 --- Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:91.0)
Gecko/20100101 Thunderbird/91.11.0
 * Origin: usenet.network (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5058/104 5075/128
@PATH: 5075/128 5020/1042 4441



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх