Nп/п : 74 из 100
 От   : db                                  2:5075/128        07 сен 23 11:49:20
 К    : pehache                                               07 сен 23 12:52:01
 Тема : Re: Calling a C++ function from Forttran
----------------------------------------------------------------------------------
                                                                                 
@MSGID: 1@dont-email.me> 08dbf438
@REPLY: <kls9koF4ootU1@mid.individual.net>
0376bb2b
@REPLYADDR db <dieterhansbritz@gmail.com>
@REPLYTO 2:5075/128 db
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: 1@dont-email.me>
@RFC-References: 1@dont-email.me>
<klobumFfoflU1@mid.individual.net> 1@dont-email.me> <kls9koF4ootU1@mid.individual.net>
@TZUTC: 0200
@PID: Mozilla/5.0 (X11; Linux x86_64; rv:102.0)
Gecko/20100101 Thunderbird/102.15.0
@TID: FIDOGATE-5.12-ge4e8b94
On 06.09.2023 23.35, pehache wrote:
> 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?

Ah, OK, I thought it mean c plus plus. I will install C++ now
and compile with G++ (i suppose).

-- 
Dieter Britz

 --- Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
 * Origin: A noiseless patient Spider (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    
                                                                                
В этой области больше нет сообщений.

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