Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Power is danger. -- The Centurion, "Balance of Terror", stardate 1709.2


devel / comp.lang.c++ / Problem with calling C++ from Fortran

SubjectAuthor
* Problem with calling C++ from Fortrandb
+* Re: Problem with calling C++ from FortranMuttley
|+* Re: Problem with calling C++ from Fortrandb
||+- Re: Problem with calling C++ from FortranMuttley
||+* Re: Problem with calling C++ from Fortrandb
|||+* Re: Problem with calling C++ from FortranMuttley
||||`* Re: Problem with calling C++ from Fortrandb
|||| +- Re: Problem with calling C++ from FortranPaavo Helde
|||| `- Re: Problem with calling C++ from FortranMuttley
|||+* Re: Problem with calling C++ from FortranPaavo Helde
||||+- Re: Problem with calling C++ from Fortrandb
||||`- Re: Problem with calling C++ from FortranJames Kuyper
|||`- Re: Problem with calling C++ from FortranBo Persson
||`- Re: Problem with calling C++ from FortranAlf P. Steinbach
|`* Re: Problem with calling C++ from Fortrandb
| `* Re: Problem with calling C++ from FortranBen Bacarisse
|  +- Re: Problem with calling C++ from FortranBen Bacarisse
|  `* Re: Problem with calling C++ from Fortrandb
|   +- Re: Problem with calling C++ from FortranMichael S
|   +- Re: Problem with calling C++ from FortranMuttley
|   `* Re: Problem with calling C++ from FortranBen Bacarisse
|    +* Re: Problem with calling C++ from Fortrandb
|    |+- Re: Problem with calling C++ from FortranBen Bacarisse
|    |`- Re: Problem with calling C++ from FortranMichael S
|    `* Re: Problem with calling C++ from FortranMichael S
|     `* Re: Problem with calling C++ from FortranBen Bacarisse
|      `* Re: Problem with calling C++ from FortranMichael S
|       `* Re: Problem with calling C++ from Fortrandb
|        `- Re: Problem with calling C++ from FortranMichael S
+- Re: Problem with calling C++ from FortranMichael S
`* Re: Problem with calling C++ from FortranMichael S
 `- Re: Problem with calling C++ from FortranMichael S

Pages:12
Problem with calling C++ from Fortran

<udhbs9$e5d$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1387&group=comp.lang.c%2B%2B#1387

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: dieterhansbritz@gmail.com (db)
Newsgroups: comp.lang.c++
Subject: Problem with calling C++ from Fortran
Date: Sat, 9 Sep 2023 10:54:33 +0200
Organization: A noiseless patient Spider
Lines: 87
Message-ID: <udhbs9$e5d$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Sep 2023 08:54:33 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d15323aad9135bc751354038a8d44b91";
logging-data="14509"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Cw41FHtu+77g12R1Y2tBg0AUILWfINok="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:aGKqPFdhIIkKLC3eKj0wDbBTBgk=
Content-Language: en-US
 by: db - Sat, 9 Sep 2023 08:54 UTC

I want to call a C++ function from Fortran. The function is
called jband, in the file jband.cpp. The function is of type
long double, and so is its argument tbar.
I wrote this:

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
FORTJBAND = JBAND (tbar)
end function FORTJBAND

I run this using this script

g++ -o jband.o jband.cpp
gfortran -o jbandtest.o jbandtest.f90
gfortran jband.o jbandtest.o
../a.out << eoi
1.0
-1
eoi
rm a.out jband.o jbandtest.o

and I get this output

/usr/bin/ld:
/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o: in
function `_start':
(.text+0x1b): undefined reference to `main'
collect2: error: ld returned 1 exit status
jbandtest.f90:21:31:

21 | import JBAND, c_long_double
| 1
Error: Cannot IMPORT 'c_long_double' from host scoping unit at (1) -
does not exist.
jbandtest.f90:22:30:

22 | import tbar, c_long_double
| 1
Error: Cannot IMPORT 'c_long_double' from host scoping unit at (1) -
does not exist.
jbandtest.f90:27:14:

27 | FORTJBAND = JBAND (tbar)
| 1
Error: Type mismatch in argument 'tbar' at (1); passed REAL(16) to REAL(4)
[...]

So there is a communication problem with agreeing on the C++
type long double.
I have tried making everything in jband plain double, making
the two statements

import JBAND, c_double
import tbar, c_double

but now it says that C-double doesn't exist.

Any ideas?

--
Dieter Britz

Re: Problem with calling C++ from Fortran

<udhcaj$j8l$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1388&group=comp.lang.c%2B%2B#1388

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Muttley@dastardlyhq.com
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Sat, 9 Sep 2023 09:02:11 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <udhcaj$j8l$1@dont-email.me>
References: <udhbs9$e5d$1@dont-email.me>
Injection-Date: Sat, 9 Sep 2023 09:02:11 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="473a55c3f815c9e7add1b6a499663345";
logging-data="19733"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187E/ncLKk/2J+NOmS08NVS"
Cancel-Lock: sha1:HW1gy1OqJ46DXe+uogWJYOxYVIA=
 by: Muttley@dastardlyhq.com - Sat, 9 Sep 2023 09:02 UTC

On Sat, 9 Sep 2023 10:54:33 +0200
db <dieterhansbritz@gmail.com> wrote:
>but now it says that C-double doesn't exist.
>
>Any ideas?

C++ mangles function names so that the name you give the function isn't the
name the dynamic loader sees in the binary. You need to put this around whatever
function you want to call from Fortran so it has C style linkage which means
the name remains the same:

extern "C" {

void calledFromFortran()
{ :
}

}

Re: Problem with calling C++ from Fortran

<udhigb$1n4d$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1389&group=comp.lang.c%2B%2B#1389

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: dieterhansbritz@gmail.com (db)
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Sat, 9 Sep 2023 12:47:38 +0200
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <udhigb$1n4d$1@dont-email.me>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Sep 2023 10:47:39 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d15323aad9135bc751354038a8d44b91";
logging-data="56461"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX186jQKTEGE3846LJAy2coo/xQmzLMdMaiM="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:knqOSHU9AjSY+H+qdTVs+lFOQ3U=
Content-Language: en-US
In-Reply-To: <udhcaj$j8l$1@dont-email.me>
 by: db - Sat, 9 Sep 2023 10:47 UTC

On 09.09.2023 11.02, Muttley@dastardlyhq.com wrote:
> On Sat, 9 Sep 2023 10:54:33 +0200
> db <dieterhansbritz@gmail.com> wrote:
>> but now it says that C-double doesn't exist.
>>
>> Any ideas?
>
> C++ mangles function names so that the name you give the function isn't the
> name the dynamic loader sees in the binary. You need to put this around whatever
> function you want to call from Fortran so it has C style linkage which means
> the name remains the same:
>
> extern "C" {
>
> void calledFromFortran()
> {
> :
> }
>
> }
>

Like this:

const long double iband(const long double tbar)
extern "C" {

void calledFromFortran()
{ :
}

}

? Why the extra } ?
--
Dieter Britz

Re: Problem with calling C++ from Fortran

<udhio7$1o70$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1390&group=comp.lang.c%2B%2B#1390

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Muttley@dastardlyhq.com
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Sat, 9 Sep 2023 10:51:52 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <udhio7$1o70$1@dont-email.me>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me> <udhigb$1n4d$1@dont-email.me>
Injection-Date: Sat, 9 Sep 2023 10:51:52 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="473a55c3f815c9e7add1b6a499663345";
logging-data="57568"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18yWmv5QtbjidsbjDKL7xY6"
Cancel-Lock: sha1:CXDvJdaTeOP32qa323LF5Q4lkHM=
 by: Muttley@dastardlyhq.com - Sat, 9 Sep 2023 10:51 UTC

On Sat, 9 Sep 2023 12:47:38 +0200
db <dieterhansbritz@gmail.com> wrote:
>On 09.09.2023 11.02, Muttley@dastardlyhq.com wrote:
>> On Sat, 9 Sep 2023 10:54:33 +0200
>> db <dieterhansbritz@gmail.com> wrote:
>>> but now it says that C-double doesn't exist.
>>>
>>> Any ideas?
>>
>> C++ mangles function names so that the name you give the function isn't the
>> name the dynamic loader sees in the binary. You need to put this around
>whatever
>> function you want to call from Fortran so it has C style linkage which means
>> the name remains the same:
>>
>> extern "C" {
>>
>> void calledFromFortran()
>> {
>> :
>> }
>>
>> }
>>
>
>Like this:

No. calledFromFortran was an example function.

extern "C" {

const long double iband(const long double tbar)
{ :
}

}

>? Why the extra } ?

What extra } ? The brackets balance.

Re: Problem with calling C++ from Fortran

<udhipr$1o3a$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1391&group=comp.lang.c%2B%2B#1391

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: dieterhansbritz@gmail.com (db)
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Sat, 9 Sep 2023 12:52:42 +0200
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <udhipr$1o3a$1@dont-email.me>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udhigb$1n4d$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 9 Sep 2023 10:52:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d15323aad9135bc751354038a8d44b91";
logging-data="57450"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196qyZCbfE0RJiv6V0MGPXEGzCQ4JIKbgE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:L0J0zfA3bBWoeLzZBI2LT8I6Q+w=
Content-Language: en-US
In-Reply-To: <udhigb$1n4d$1@dont-email.me>
 by: db - Sat, 9 Sep 2023 10:52 UTC

On 09.09.2023 12.47, db wrote:
> On 09.09.2023 11.02, Muttley@dastardlyhq.com wrote:
>> On Sat, 9 Sep 2023 10:54:33 +0200
>> db <dieterhansbritz@gmail.com> wrote:
>>> but now it says that C-double doesn't exist.
>>>
>>> Any ideas?
>>
>> C++ mangles function names so that the name you give the function
>> isn't the
>> name the dynamic loader sees in the binary. You need to put this
>> around whatever
>> function you want to call from Fortran so it has C style linkage which
>> means
>> the name remains the same:
>>
>> extern "C" {
>>
>> void calledFromFortran()
>> {
>>     :
>> }
>>
>> }
>>
>
> Like this:
>
> const long double iband(const long double tbar)
> extern "C" {
>
> void calledFromFortran()
> {
>     :
> }
>
> }
>
> ? Why the extra } ?

Now I get a new error, due to this "extern"

~/ownlib90/tests> ./jbandtest
jband.cpp:88:1: error: expected initializer before 'extern'
88 | extern "C" {
| ^~~~~~
jband.cpp:96:1: error: expected unqualified-id before '{' token
96 | {
| ^
jbandtest.f90:21:31:

21 | import JBAND, c_long_double
| 1
Error: Cannot IMPORT 'c_long_double' from host scoping unit at (1) -
does not exist.
[...]

--
Dieter Britz

Re: Problem with calling C++ from Fortran

<udhj7o$1qkq$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1392&group=comp.lang.c%2B%2B#1392

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Muttley@dastardlyhq.com
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Sat, 9 Sep 2023 11:00:08 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <udhj7o$1qkq$1@dont-email.me>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udhigb$1n4d$1@dont-email.me>
<udhipr$1o3a$1@dont-email.me>
Injection-Date: Sat, 9 Sep 2023 11:00:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="473a55c3f815c9e7add1b6a499663345";
logging-data="60058"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8N3ucuG+FljB0vzN2lXp1"
Cancel-Lock: sha1:0SEFwdAC0lon/FVBlXGAsGeol+k=
 by: Muttley@dastardlyhq.com - Sat, 9 Sep 2023 11:00 UTC

On Sat, 9 Sep 2023 12:52:42 +0200
db <dieterhansbritz@gmail.com> wrote:
>On 09.09.2023 12.47, db wrote:
>Now I get a new error, due to this "extern"
>
>~/ownlib90/tests> ./jbandtest
>jband.cpp:88:1: error: expected initializer before 'extern'
> 88 | extern "C" {
> | ^~~~~~
>jband.cpp:96:1: error: expected unqualified-id before '{' token
> 96 | {
> | ^
>jbandtest.f90:21:31:
>
> 21 | import JBAND, c_long_double
> | 1
>Error: Cannot IMPORT 'c_long_double' from host scoping unit at (1) -
>does not exist.
>[...]

If your knowledge of C++ syntax is so basic you don't know which bits go
where I'd suggest getting someone else to write the C++ code and you stick
to fortran.

Re: Problem with calling C++ from Fortran

<udhthr$3dir$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1393&group=comp.lang.c%2B%2B#1393

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: eesnimi@osa.pri.ee (Paavo Helde)
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Sat, 9 Sep 2023 16:56:10 +0300
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <udhthr$3dir$1@dont-email.me>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udhigb$1n4d$1@dont-email.me> <udhipr$1o3a$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 9 Sep 2023 13:56:11 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0d36706b697ad2c8a892f9a52886dcec";
logging-data="112219"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hvwIriNelHOa8q+4NvxWspzqUnrHsuwM="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:1eYSF2ma+blKSW8A662KnKrHB9U=
In-Reply-To: <udhipr$1o3a$1@dont-email.me>
Content-Language: en-US
 by: Paavo Helde - Sat, 9 Sep 2023 13:56 UTC

09.09.2023 13:52 db kirjutas:
> On 09.09.2023 12.47, db wrote:
>> On 09.09.2023 11.02, Muttley@dastardlyhq.com wrote:
>>> On Sat, 9 Sep 2023 10:54:33 +0200
>>> db <dieterhansbritz@gmail.com> wrote:
>>>> but now it says that C-double doesn't exist.
>>>>
>>>> Any ideas?
>>>
>>> C++ mangles function names so that the name you give the function
>>> isn't the
>>> name the dynamic loader sees in the binary. You need to put this
>>> around whatever
>>> function you want to call from Fortran so it has C style linkage
>>> which means
>>> the name remains the same:
>>>
>>> extern "C" {
>>>
>>> void calledFromFortran()
>>> {
>>>     :
>>> }
>>>
>>> }
>>>
>>
>> Like this:
>>
>> const long double iband(const long double tbar)
>> extern "C" {
>>
>> void calledFromFortran()
>> {
>>      :
>> }
>>
>> }
>>
>> ? Why the extra } ?
>
> Now I get a new error, due to this "extern"
>
> ~/ownlib90/tests> ./jbandtest
> jband.cpp:88:1: error: expected initializer before 'extern'
>    88 | extern "C" {
>       | ^~~~~~
> jband.cpp:96:1: error: expected unqualified-id before '{' token
>    96 | {
>       | ^

Assuming you are indeed compiling this as C++ as intended, the problem
must be with the preceding content.

> jbandtest.f90:21:31:
>
>    21 |     import JBAND, c_long_double
>       |                               1
> Error: Cannot IMPORT 'c_long_double' from host scoping unit at (1) -
> does not exist.
> [...]

This is a fortran error message. It's not very likely you will get any
help about this here, most people here do not know anything about fortran.

Re: Problem with calling C++ from Fortran

<udhvia$41ae$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1394&group=comp.lang.c%2B%2B#1394

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: alf.p.steinbach@gmail.com (Alf P. Steinbach)
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Sat, 9 Sep 2023 16:30:34 +0200
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <udhvia$41ae$1@dont-email.me>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udhigb$1n4d$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 9 Sep 2023 14:30:34 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e5e0058f89eb6faa1855f7325c0ca33f";
logging-data="132430"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18vxV2cltcLnNfL2bDjuoS9"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:cTj2srLlY+9fosxhtL9XxQAmTK0=
In-Reply-To: <udhigb$1n4d$1@dont-email.me>
Content-Language: en-US
 by: Alf P. Steinbach - Sat, 9 Sep 2023 14:30 UTC

On 2023-09-09 12:47 PM, db wrote:
> On 09.09.2023 11.02, Muttley@dastardlyhq.com wrote:
>> On Sat, 9 Sep 2023 10:54:33 +0200
>> db <dieterhansbritz@gmail.com> wrote:
>>> but now it says that C-double doesn't exist.
>>>
>>> Any ideas?
>>
>> C++ mangles function names so that the name you give the function
>> isn't the
>> name the dynamic loader sees in the binary. You need to put this
>> around whatever
>> function you want to call from Fortran so it has C style linkage which
>> means
>> the name remains the same:
>>
>> extern "C" {
>>
>> void calledFromFortran()
>> {
>>     :
>> }
>>
>> }
>>
>
> Like this:
>
> const long double iband(const long double tbar)

Why did you add that?

You could at least try to do /exactly/ the example given by a
knowledgeable person.

> extern "C" {
>
> void calledFromFortran()
> {
>     :
> }
>
> }
>
> ? Why the extra } ?

Re: Problem with calling C++ from Fortran

<udkd2m$iokr$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1419&group=comp.lang.c%2B%2B#1419

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: dieterhansbritz@gmail.com (db)
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Sun, 10 Sep 2023 14:33:26 +0200
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <udkd2m$iokr$1@dont-email.me>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udhigb$1n4d$1@dont-email.me> <udhipr$1o3a$1@dont-email.me>
<udhj7o$1qkq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Sep 2023 12:33:27 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d71524a6642a219e941a336e8f99fffc";
logging-data="615067"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19FI7ii59/2isd/oWhXcsf3K2heyRCsbdw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:5ynsbgpIB2Wt2SAdjbGUvuPTMdo=
Content-Language: en-US
In-Reply-To: <udhj7o$1qkq$1@dont-email.me>
 by: db - Sun, 10 Sep 2023 12:33 UTC

On 09.09.2023 13.00, Muttley@dastardlyhq.com wrote:
> On Sat, 9 Sep 2023 12:52:42 +0200
> db <dieterhansbritz@gmail.com> wrote:
>> On 09.09.2023 12.47, db wrote:
>> Now I get a new error, due to this "extern"
>>
>> ~/ownlib90/tests> ./jbandtest
>> jband.cpp:88:1: error: expected initializer before 'extern'
>> 88 | extern "C" {
>> | ^~~~~~
>> jband.cpp:96:1: error: expected unqualified-id before '{' token
>> 96 | {
>> | ^
>> jbandtest.f90:21:31:
>>
>> 21 | import JBAND, c_long_double
>> | 1
>> Error: Cannot IMPORT 'c_long_double' from host scoping unit at (1) -
>> does not exist.
>> [...]
>
> If your knowledge of C++ syntax is so basic you don't know which bits go
> where I'd suggest getting someone else to write the C++ code and you stick
> to fortran.
>

An unhelpful comment..
The C++ function was written by an experienced C++
programmer, and my problem is calling it from Fortran.
OK, I missed the extra opening {. The problem lies
in the communication between Fortran and C++.
--
Dieter Britz

Re: Problem with calling C++ from Fortran

<udkd83$iokr$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1420&group=comp.lang.c%2B%2B#1420

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: dieterhansbritz@gmail.com (db)
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Sun, 10 Sep 2023 14:36:19 +0200
Organization: A noiseless patient Spider
Lines: 74
Message-ID: <udkd83$iokr$2@dont-email.me>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udhigb$1n4d$1@dont-email.me> <udhipr$1o3a$1@dont-email.me>
<udhthr$3dir$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 10 Sep 2023 12:36:19 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d71524a6642a219e941a336e8f99fffc";
logging-data="615067"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+5lv1SoU0mYIuh8LLMMbs5zSFq0ltf0pY="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:s5n9hSEC6GhvR+MTfeZhieLib9s=
Content-Language: en-US
In-Reply-To: <udhthr$3dir$1@dont-email.me>
 by: db - Sun, 10 Sep 2023 12:36 UTC

On 09.09.2023 15.56, Paavo Helde wrote:
> 09.09.2023 13:52 db kirjutas:
>> On 09.09.2023 12.47, db wrote:
>>> On 09.09.2023 11.02, Muttley@dastardlyhq.com wrote:
>>>> On Sat, 9 Sep 2023 10:54:33 +0200
>>>> db <dieterhansbritz@gmail.com> wrote:
>>>>> but now it says that C-double doesn't exist.
>>>>>
>>>>> Any ideas?
>>>>
>>>> C++ mangles function names so that the name you give the function
>>>> isn't the
>>>> name the dynamic loader sees in the binary. You need to put this
>>>> around whatever
>>>> function you want to call from Fortran so it has C style linkage
>>>> which means
>>>> the name remains the same:
>>>>
>>>> extern "C" {
>>>>
>>>> void calledFromFortran()
>>>> {
>>>>     :
>>>> }
>>>>
>>>> }
>>>>
>>>
>>> Like this:
>>>
>>> const long double iband(const long double tbar)
>>> extern "C" {
>>>
>>> void calledFromFortran()
>>> {
>>>      :
>>> }
>>>
>>> }
>>>
>>> ? Why the extra } ?
>>
>> Now I get a new error, due to this "extern"
>>
>> ~/ownlib90/tests> ./jbandtest
>> jband.cpp:88:1: error: expected initializer before 'extern'
>>     88 | extern "C" {
>>        | ^~~~~~
>> jband.cpp:96:1: error: expected unqualified-id before '{' token
>>     96 | {
>>        | ^
>
> Assuming you are indeed compiling this as C++ as intended, the problem
> must be with the preceding content.
>
>> jbandtest.f90:21:31:
>>
>>     21 |     import JBAND, c_long_double
>>        |                               1
>> Error: Cannot IMPORT 'c_long_double' from host scoping unit at (1) -
>> does not exist.
>> [...]
>
> This is a fortran error message. It's not very likely you will get any
> help about this here, most people here do not know anything about fortran.
>
I have tried that but so far no one was able to help there,
so I thought I'd try at the other end. No go here either.
Ar well, I might have to myself translate the C++ code into
Fortran. I have done that with another routine and it was
quite laborious.
--
Dieter Britz

Re: Problem with calling C++ from Fortran

<udkdu9$itm4$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1421&group=comp.lang.c%2B%2B#1421

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: dieterhansbritz@gmail.com (db)
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Sun, 10 Sep 2023 14:48:09 +0200
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <udkdu9$itm4$1@dont-email.me>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Sep 2023 12:48:09 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d71524a6642a219e941a336e8f99fffc";
logging-data="620228"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18p+mVGyyTjVOQicugRRQi/3rfAK23mHRc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:Adb/cONt6fZOGY3UlaIDphD1NLA=
In-Reply-To: <udhcaj$j8l$1@dont-email.me>
Content-Language: en-US
 by: db - Sun, 10 Sep 2023 12:48 UTC

On 09.09.2023 11.02, Muttley@dastardlyhq.com wrote:
> On Sat, 9 Sep 2023 10:54:33 +0200
> db <dieterhansbritz@gmail.com> wrote:
>> but now it says that C-double doesn't exist.
>>
>> Any ideas?
>
> C++ mangles function names so that the name you give the function isn't the
> name the dynamic loader sees in the binary. You need to put this around whatever
> function you want to call from Fortran so it has C style linkage which means
> the name remains the same:
>
> extern "C" {
>
> void calledFromFortran()
> {
> :
> }
>
> }
>
Where should this go in the code? I added it at the end as is,
and now I get this:

~/ownlib90/tests> ./jbandtest
jband.cpp:88:1: error: expected initializer before 'extern'
88 | extern "C" {
| ^~~~~~
jband.cpp:96:1: error: expected unqualified-id before '{' token
96 | {
| ^
jband.cpp: In function 'void calledFromFortran()':
jband.cpp:350:9: error: expected primary-expression before ':' token
350 | :
...

--
Dieter Britz

Re: Problem with calling C++ from Fortran

<87o7iajh8b.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1422&group=comp.lang.c%2B%2B#1422

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Sun, 10 Sep 2023 14:22:12 +0100
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <87o7iajh8b.fsf@bsb.me.uk>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udkdu9$itm4$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="871ee901e005cd01e5d2484bc26cd51b";
logging-data="629398"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Lnv2oezsOVhuVR2TXssue5iGEy4++eis="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:BIh4NBbjzpHEndeqLNqqx84r4uw=
sha1:CGn93J3JDeLS63q6BxnVCJKAwDU=
X-BSB-Auth: 1.344564da97a02fed77b0.20230910142212BST.87o7iajh8b.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 10 Sep 2023 13:22 UTC

db <dieterhansbritz@gmail.com> writes:

> On 09.09.2023 11.02, Muttley@dastardlyhq.com wrote:
>> On Sat, 9 Sep 2023 10:54:33 +0200
>> db <dieterhansbritz@gmail.com> wrote:
>>> but now it says that C-double doesn't exist.
>>>
>>> Any ideas?
>> C++ mangles function names so that the name you give the function isn't
>> the
>> name the dynamic loader sees in the binary. You need to put this around whatever
>> function you want to call from Fortran so it has C style linkage which means
>> the name remains the same:
>> extern "C" {
>> void calledFromFortran()
>> {
>> :
>> }
>> }
>>
> Where should this go in the code? I added it at the end as is,
> and now I get this:
>
> ~/ownlib90/tests> ./jbandtest
> jband.cpp:88:1: error: expected initializer before 'extern'
> 88 | extern "C" {
> | ^~~~~~
> jband.cpp:96:1: error: expected unqualified-id before '{' token
> 96 | {
> | ^
> jband.cpp: In function 'void calledFromFortran()':
> jband.cpp:350:9: error: expected primary-expression before ':' token
> 350 | :
> ...

You are giving people very little to go on. There's an unknown command
(./jbandtest) the gives some errors where only one line of code can be
seen.

Can you produce a cut-down version to the program that shows the same
error -- mimimal example of the C++ and of the Fortran that should
calls it but which fails? That would mean you could post the code.

If that is not possible, can you link to the source so those who know
both C++ and Fortran can take a proper look?

--
Ben.

Re: Problem with calling C++ from Fortran

<km60u6Floj6U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1424&group=comp.lang.c%2B%2B#1424

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: bo@bo-persson.se (Bo Persson)
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Sun, 10 Sep 2023 16:08:06 +0200
Lines: 52
Message-ID: <km60u6Floj6U1@mid.individual.net>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udhigb$1n4d$1@dont-email.me> <udhipr$1o3a$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net tOA6r6Oc70clsnhX0uwxug0IOLRxKiLljkWvxi2GKu7Z8FtdUJ
Cancel-Lock: sha1:nGr5VzZ3hSYco+cz+O6NYBcnOWs= sha256:X+DvlhdFmgs3BhTOkkmQgApREWzF9OJnVlSx62EEloY=
User-Agent: Mozilla Thunderbird
Content-Language: sv
In-Reply-To: <udhipr$1o3a$1@dont-email.me>
 by: Bo Persson - Sun, 10 Sep 2023 14:08 UTC

On 2023-09-09 at 12:52, db wrote:
> On 09.09.2023 12.47, db wrote:
>> On 09.09.2023 11.02, Muttley@dastardlyhq.com wrote:
>>> On Sat, 9 Sep 2023 10:54:33 +0200
>>> db <dieterhansbritz@gmail.com> wrote:
>>>> but now it says that C-double doesn't exist.
>>>>
>>>> Any ideas?
>>>
>>> C++ mangles function names so that the name you give the function
>>> isn't the
>>> name the dynamic loader sees in the binary. You need to put this
>>> around whatever
>>> function you want to call from Fortran so it has C style linkage
>>> which means
>>> the name remains the same:
>>>
>>> extern "C" {
>>>
>>> void calledFromFortran()
>>> {
>>>     :
>>> }
>>>
>>> }
>>>
>>
>> Like this:
>>
>> const long double iband(const long double tbar)
>> extern "C" {
>>
>> void calledFromFortran()
>> {
>>      :
>> }
>>
>> }
>>
>> ? Why the extra } ?
>
> Now I get a new error, due to this "extern"
>
> ~/ownlib90/tests> ./jbandtest
> jband.cpp:88:1: error: expected initializer before 'extern'
>    88 | extern "C" {
>       | ^~~~~~

I wild guess here is that the line *before* this is where something is
missing. The message is just that 'extern' was not expected here, but
something else.

Re: Problem with calling C++ from Fortran

<0765ca71-5d8b-4f0f-9287-f3de55271ac1n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1425&group=comp.lang.c%2B%2B#1425

  copy link   Newsgroups: comp.lang.c++
X-Received: by 2002:ac8:4e52:0:b0:411:fa3c:358e with SMTP id e18-20020ac84e52000000b00411fa3c358emr172926qtw.13.1694360308241;
Sun, 10 Sep 2023 08:38:28 -0700 (PDT)
X-Received: by 2002:a17:902:f686:b0:1bb:91c9:d334 with SMTP id
l6-20020a170902f68600b001bb91c9d334mr2889573plg.0.1694360308008; Sun, 10 Sep
2023 08:38:28 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c++
Date: Sun, 10 Sep 2023 08:38:27 -0700 (PDT)
In-Reply-To: <udhbs9$e5d$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=199.203.251.52; posting-account=ow8VOgoAAAAfiGNvoH__Y4ADRwQF1hZW
NNTP-Posting-Host: 199.203.251.52
References: <udhbs9$e5d$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0765ca71-5d8b-4f0f-9287-f3de55271ac1n@googlegroups.com>
Subject: Re: Problem with calling C++ from Fortran
From: already5chosen@yahoo.com (Michael S)
Injection-Date: Sun, 10 Sep 2023 15:38:28 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3671
 by: Michael S - Sun, 10 Sep 2023 15:38 UTC

On Saturday, September 9, 2023 at 11:54:53 AM UTC+3, db wrote:
> I want to call a C++ function from Fortran. The function is
> called jband, in the file jband.cpp. The function is of type
> long double, and so is its argument tbar.
> I wrote this:
>
> 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
> FORTJBAND = JBAND (tbar)
> end function FORTJBAND
>
> I run this using this script
>
> g++ -o jband.o jband.cpp

That's command is wrong. Should be:
g++ -c -o jband.o jband.cpp

> gfortran -o jbandtest.o jbandtest.f90
> gfortran jband.o jbandtest.o
> ./a.out << eoi
> 1.0
> -1
> eoi
> rm a.out jband.o jbandtest.o
>
> and I get this output
>
> /usr/bin/ld:
> /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o: in
> function `_start':
> (.text+0x1b): undefined reference to `main'
> collect2: error: ld returned 1 exit status
> jbandtest.f90:21:31:
>
> 21 | import JBAND, c_long_double
> | 1
> Error: Cannot IMPORT 'c_long_double' from host scoping unit at (1) -
> does not exist.
> jbandtest.f90:22:30:
>
> 22 | import tbar, c_long_double
> | 1
> Error: Cannot IMPORT 'c_long_double' from host scoping unit at (1) -
> does not exist.
> jbandtest.f90:27:14:
>
> 27 | FORTJBAND = JBAND (tbar)
> | 1
> Error: Type mismatch in argument 'tbar' at (1); passed REAL(16) to REAL(4)
> [...]
>
> So there is a communication problem with agreeing on the C++
> type long double.
> I have tried making everything in jband plain double, making
> the two statements
>
> import JBAND, c_double
> import tbar, c_double
>
> but now it says that C-double doesn't exist.
>
> Any ideas?
>
>
>
> --
> Dieter Britz

Re: Problem with calling C++ from Fortran

<udkohd$kf94$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1427&group=comp.lang.c%2B%2B#1427

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: eesnimi@osa.pri.ee (Paavo Helde)
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Sun, 10 Sep 2023 18:49:00 +0300
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <udkohd$kf94$1@dont-email.me>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udhigb$1n4d$1@dont-email.me> <udhipr$1o3a$1@dont-email.me>
<udhj7o$1qkq$1@dont-email.me> <udkd2m$iokr$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Sep 2023 15:49:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="7abe9392a749e386a1f2f35554478286";
logging-data="671012"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1+5Sl/F0mzhe1NpoMpTdM7RqSnuEBbSc="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:QtFPmnGIu6vjCnQeOTEXOrGpzL4=
Content-Language: en-US
In-Reply-To: <udkd2m$iokr$1@dont-email.me>
 by: Paavo Helde - Sun, 10 Sep 2023 15:49 UTC

10.09.2023 15:33 db kirjutas:

> The C++ function was written by an experienced C++
> programmer, and my problem is calling it from Fortran.
> OK, I missed the extra opening {. The problem lies
> in the communication between Fortran and C++.

From C++ side it's necessary to declare and compile the function extern
"C" and it must be exported from the resulting shared library (by
__declspec(dllexport) or __attribute__ ((visibility ("default"))),
depending on the platform).

For sure an experienced C++ programmer is able to do that easily. After
that, the ball is on the Fortran side.

Re: Problem with calling C++ from Fortran

<87il8ij8n5.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1430&group=comp.lang.c%2B%2B#1430

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Sun, 10 Sep 2023 17:27:42 +0100
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <87il8ij8n5.fsf@bsb.me.uk>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udkdu9$itm4$1@dont-email.me> <87o7iajh8b.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="871ee901e005cd01e5d2484bc26cd51b";
logging-data="684672"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+z9iK46fFrSH1n6rTSgGzJ7BeRboSWx/o="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:rGlkuatjbMAafD81QLDeTDe5v30=
sha1:FRmOwnVsZEvecFi6ywC3SwjechE=
X-BSB-Auth: 1.aea0c45281552c7dd102.20230910172742BST.87il8ij8n5.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 10 Sep 2023 16:27 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> db <dieterhansbritz@gmail.com> writes:
>
>> On 09.09.2023 11.02, Muttley@dastardlyhq.com wrote:
>>> On Sat, 9 Sep 2023 10:54:33 +0200
>>> db <dieterhansbritz@gmail.com> wrote:
>>>> but now it says that C-double doesn't exist.
>>>>
>>>> Any ideas?
>>> C++ mangles function names so that the name you give the function isn't
>>> the
>>> name the dynamic loader sees in the binary. You need to put this around whatever
>>> function you want to call from Fortran so it has C style linkage which means
>>> the name remains the same:
>>> extern "C" {
>>> void calledFromFortran()
>>> {
>>> :
>>> }
>>> }
>>>
>> Where should this go in the code? I added it at the end as is,
>> and now I get this:
>>
>> ~/ownlib90/tests> ./jbandtest
>> jband.cpp:88:1: error: expected initializer before 'extern'
>> 88 | extern "C" {
>> | ^~~~~~
>> jband.cpp:96:1: error: expected unqualified-id before '{' token
>> 96 | {
>> | ^
>> jband.cpp: In function 'void calledFromFortran()':
>> jband.cpp:350:9: error: expected primary-expression before ':' token
>> 350 | :
>> ...
>
> You are giving people very little to go on. There's an unknown command
> (./jbandtest) the gives some errors where only one line of code can be
> seen.
>
> Can you produce a cut-down version to the program that shows the same
> error -- mimimal example of the C++ and of the Fortran that should
> calls it but which fails? That would mean you could post the code.

I see you have indeed posted half of it. If you post the C++ source,
someone might be able to help with both parts. I can tell you a bit
about what's wrong with the Fortran you posted, but I need to see the
other half.

--
Ben.

Re: Problem with calling C++ from Fortran

<1cb73971-2d9b-45c7-819a-51ee45913456n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1432&group=comp.lang.c%2B%2B#1432

  copy link   Newsgroups: comp.lang.c++
X-Received: by 2002:a0c:e648:0:b0:646:eace:a17d with SMTP id c8-20020a0ce648000000b00646eacea17dmr307102qvn.1.1694364703865;
Sun, 10 Sep 2023 09:51:43 -0700 (PDT)
X-Received: by 2002:a05:6a00:150b:b0:68a:2c24:57ce with SMTP id
q11-20020a056a00150b00b0068a2c2457cemr3095556pfu.5.1694364703563; Sun, 10 Sep
2023 09:51:43 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c++
Date: Sun, 10 Sep 2023 09:51:42 -0700 (PDT)
In-Reply-To: <udhbs9$e5d$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=199.203.251.52; posting-account=ow8VOgoAAAAfiGNvoH__Y4ADRwQF1hZW
NNTP-Posting-Host: 199.203.251.52
References: <udhbs9$e5d$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1cb73971-2d9b-45c7-819a-51ee45913456n@googlegroups.com>
Subject: Re: Problem with calling C++ from Fortran
From: already5chosen@yahoo.com (Michael S)
Injection-Date: Sun, 10 Sep 2023 16:51:43 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 149
 by: Michael S - Sun, 10 Sep 2023 16:51 UTC

On Saturday, September 9, 2023 at 11:54:53 AM UTC+3, db wrote:
> I want to call a C++ function from Fortran. The function is
> called jband, in the file jband.cpp. The function is of type
> long double, and so is its argument tbar.
> I wrote this:
>
> 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
> FORTJBAND = JBAND (tbar)
> end function FORTJBAND
>
> I run this using this script
>
> g++ -o jband.o jband.cpp
> gfortran -o jbandtest.o jbandtest.f90
> gfortran jband.o jbandtest.o
> ./a.out << eoi
> 1.0
> -1
> eoi
> rm a.out jband.o jbandtest.o
>
> and I get this output
>
> /usr/bin/ld:
> /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o: in
> function `_start':
> (.text+0x1b): undefined reference to `main'
> collect2: error: ld returned 1 exit status
> jbandtest.f90:21:31:
>
> 21 | import JBAND, c_long_double
> | 1
> Error: Cannot IMPORT 'c_long_double' from host scoping unit at (1) -
> does not exist.
> jbandtest.f90:22:30:
>
> 22 | import tbar, c_long_double
> | 1
> Error: Cannot IMPORT 'c_long_double' from host scoping unit at (1) -
> does not exist.
> jbandtest.f90:27:14:
>
> 27 | FORTJBAND = JBAND (tbar)
> | 1
> Error: Type mismatch in argument 'tbar' at (1); passed REAL(16) to REAL(4)
> [...]
>
> So there is a communication problem with agreeing on the C++
> type long double.
> I have tried making everything in jband plain double, making
> the two statements
>
> import JBAND, c_double
> import tbar, c_double
>
> but now it says that C-double doesn't exist.
>
> Any ideas?
>
>
>
> --
> Dieter Britz

I manged to pass link. 99% of the problems appear to have nothing to do
with C++ language. It's partly bad Fortran, partly wrong size of floating-point
types and partly forgotten -c flag in compilation commands.

That's my Fortran (f90) source code:

module STUFF
integer, parameter :: dbl=selected_real_kind(14)
integer, parameter :: qud=selected_real_kind(30)
end module STUFF

module abc
use, intrinsic :: iso_c_binding
interface
function JBAND (tbar) bind(c)
import c_long_double
real(c_long_double) :: JBAND
real(c_long_double) :: tbar
end function JBAND
end interface
end module abc

function FORTJBAND (tbar)
use STUFF;
use abc;
implicit none
real(dbl) :: FORTJBAND
real(qud) :: tbar
real(10) :: tbar10
real(10) :: res10
tbar10 = tbar
res10 = JBAND (tbar10)
FORTJBAND = res10
end function FORTJBAND

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

That's my C++ source code (1 line)
extern "C" long double jband(long double x) { return x; }

That's my compilation commands:
g++ -c -o jband.o jband.cpp
gfortran -c -o jbandtest.o jbandtest.f90
gfortran jband.o jbandtest.o

Now I have no idea if it works like intended or not

Re: Problem with calling C++ from Fortran

<udm475$u0mo$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1446&group=comp.lang.c%2B%2B#1446

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuyper@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Mon, 11 Sep 2023 00:14:29 -0400
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <udm475$u0mo$1@dont-email.me>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udhigb$1n4d$1@dont-email.me> <udhipr$1o3a$1@dont-email.me>
<udhthr$3dir$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 11 Sep 2023 04:14:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cca80aa8964a9f7f1f5b653a003d40ef";
logging-data="983768"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5zgwNKRPqdkeU3gI01+lXi6E0t1alYnw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:ajr/Z1TKhEArKHu+QV/zZWSQK/k=
Content-Language: en-US
In-Reply-To: <udhthr$3dir$1@dont-email.me>
 by: James Kuyper - Mon, 11 Sep 2023 04:14 UTC

While "C" and "C++" are the only language linkages for which support is
mandated by the standard, the description of language linkage is clearly
intended to allow support for a wider range of language linkages. Could
anyone tell me which implementatins, if any, support language linkages
other than "C" and C++"? If so, what languages do they support? How well
does the feature work? Is there any significant amount of use relying on
that feature?
In particular, and relevant to this thread, does any implementation
support "Fortran" language linkage?

Re: Problem with calling C++ from Fortran

<udmipr$vtg5$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1449&group=comp.lang.c%2B%2B#1449

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Muttley@dastardlyhq.com
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Mon, 11 Sep 2023 08:23:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <udmipr$vtg5$1@dont-email.me>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udhigb$1n4d$1@dont-email.me> <udhipr$1o3a$1@dont-email.me>
<udhj7o$1qkq$1@dont-email.me>
<udkd2m$iokr$1@dont-email.me>
Injection-Date: Mon, 11 Sep 2023 08:23:23 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="5fa00f5afe82d78c34565b5d5b1eaa90";
logging-data="1046021"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX189KaSjleGGXGAWisG6v3vU"
Cancel-Lock: sha1:jb+27STp5LcTiLHJrL3hRFDMa0g=
 by: Muttley@dastardlyhq.com - Mon, 11 Sep 2023 08:23 UTC

On Sun, 10 Sep 2023 14:33:26 +0200
db <dieterhansbritz@gmail.com> wrote:
>On 09.09.2023 13.00, Muttley@dastardlyhq.com wrote:
>> On Sat, 9 Sep 2023 12:52:42 +0200
>> db <dieterhansbritz@gmail.com> wrote:
>>> On 09.09.2023 12.47, db wrote:
>>> Now I get a new error, due to this "extern"
>>>
>>> ~/ownlib90/tests> ./jbandtest
>>> jband.cpp:88:1: error: expected initializer before 'extern'
>>> 88 | extern "C" {
>>> | ^~~~~~
>>> jband.cpp:96:1: error: expected unqualified-id before '{' token
>>> 96 | {
>>> | ^
>>> jbandtest.f90:21:31:
>>>
>>> 21 | import JBAND, c_long_double
>>> | 1
>>> Error: Cannot IMPORT 'c_long_double' from host scoping unit at (1) -
>>> does not exist.
>>> [...]
>>
>> If your knowledge of C++ syntax is so basic you don't know which bits go
>> where I'd suggest getting someone else to write the C++ code and you stick
>> to fortran.
>>
>
>An unhelpful comment..
>The C++ function was written by an experienced C++
>programmer, and my problem is calling it from Fortran.
>OK, I missed the extra opening {. The problem lies
>in the communication between Fortran and C++.

If you're having trouble with this kind of basic stuff I think you're going
to have a lot more problems down the line with this.

If you're in contact with the guy who wrote the C++ code I would suggest
talking to him about it.

Re: Problem with calling C++ from Fortran

<5b90a0f9-0da7-425b-ae83-779459f0f50en@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1450&group=comp.lang.c%2B%2B#1450

  copy link   Newsgroups: comp.lang.c++
X-Received: by 2002:a05:622a:2c6:b0:412:1318:9d4f with SMTP id a6-20020a05622a02c600b0041213189d4fmr231221qtx.2.1694425771060;
Mon, 11 Sep 2023 02:49:31 -0700 (PDT)
X-Received: by 2002:a05:6a00:2da1:b0:68e:245e:7437 with SMTP id
fb33-20020a056a002da100b0068e245e7437mr3589077pfb.2.1694425770514; Mon, 11
Sep 2023 02:49:30 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c++
Date: Mon, 11 Sep 2023 02:49:29 -0700 (PDT)
In-Reply-To: <1cb73971-2d9b-45c7-819a-51ee45913456n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=199.203.251.52; posting-account=ow8VOgoAAAAfiGNvoH__Y4ADRwQF1hZW
NNTP-Posting-Host: 199.203.251.52
References: <udhbs9$e5d$1@dont-email.me> <1cb73971-2d9b-45c7-819a-51ee45913456n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5b90a0f9-0da7-425b-ae83-779459f0f50en@googlegroups.com>
Subject: Re: Problem with calling C++ from Fortran
From: already5chosen@yahoo.com (Michael S)
Injection-Date: Mon, 11 Sep 2023 09:49:31 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 6102
 by: Michael S - Mon, 11 Sep 2023 09:49 UTC

On Sunday, September 10, 2023 at 7:51:56 PM UTC+3, Michael S wrote:
> On Saturday, September 9, 2023 at 11:54:53 AM UTC+3, db wrote:
> > I want to call a C++ function from Fortran. The function is
> > called jband, in the file jband.cpp. The function is of type
> > long double, and so is its argument tbar.
> > I wrote this:
> >
> > 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
> > FORTJBAND = JBAND (tbar)
> > end function FORTJBAND
> >
> > I run this using this script
> >
> > g++ -o jband.o jband.cpp
> > gfortran -o jbandtest.o jbandtest.f90
> > gfortran jband.o jbandtest.o
> > ./a.out << eoi
> > 1.0
> > -1
> > eoi
> > rm a.out jband.o jbandtest.o
> >
> > and I get this output
> >
> > /usr/bin/ld:
> > /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o: in
> > function `_start':
> > (.text+0x1b): undefined reference to `main'
> > collect2: error: ld returned 1 exit status
> > jbandtest.f90:21:31:
> >
> > 21 | import JBAND, c_long_double
> > | 1
> > Error: Cannot IMPORT 'c_long_double' from host scoping unit at (1) -
> > does not exist.
> > jbandtest.f90:22:30:
> >
> > 22 | import tbar, c_long_double
> > | 1
> > Error: Cannot IMPORT 'c_long_double' from host scoping unit at (1) -
> > does not exist.
> > jbandtest.f90:27:14:
> >
> > 27 | FORTJBAND = JBAND (tbar)
> > | 1
> > Error: Type mismatch in argument 'tbar' at (1); passed REAL(16) to REAL(4)
> > [...]
> >
> > So there is a communication problem with agreeing on the C++
> > type long double.
> > I have tried making everything in jband plain double, making
> > the two statements
> >
> > import JBAND, c_double
> > import tbar, c_double
> >
> > but now it says that C-double doesn't exist.
> >
> > Any ideas?
> >
> >
> >
> > --
> > Dieter Britz
> I manged to pass link. 99% of the problems appear to have nothing to do
> with C++ language. It's partly bad Fortran, partly wrong size of floating-point
> types and partly forgotten -c flag in compilation commands.
>
> That's my Fortran (f90) source code:
> module STUFF
> integer, parameter :: dbl=selected_real_kind(14)
> integer, parameter :: qud=selected_real_kind(30)
> end module STUFF
> module abc
> use, intrinsic :: iso_c_binding
> interface
> function JBAND (tbar) bind(c)
> import c_long_double
> real(c_long_double) :: JBAND
> real(c_long_double) :: tbar
> end function JBAND
> end interface
> end module abc
> function FORTJBAND (tbar)
> use STUFF;
> use abc;
> implicit none
> real(dbl) :: FORTJBAND
> real(qud) :: tbar
> real(10) :: tbar10
> real(10) :: res10
> tbar10 = tbar
> res10 = JBAND (tbar10)
> FORTJBAND = res10
> end function FORTJBAND
> 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
> That's my C++ source code (1 line)
> extern "C" long double jband(long double x) { return x; }
>
> That's my compilation commands:
> g++ -c -o jband.o jband.cpp
> gfortran -c -o jbandtest.o jbandtest.f90
> gfortran jband.o jbandtest.o
>
> Now I have no idea if it works like intended or not

Tested it. It was incorrect, but by lucky chance worked on x86-64 Windows.
No such luck on x86-64 Linux.
Here is the correct syntax that works both on Windows and on Linux:

module abc
use, intrinsic :: iso_c_binding
interface
real(c_long_double) function JBAND (tbar) bind(c)
import c_long_double
real(c_long_double), value :: tbar
end function JBAND
end interface
end module abc

I actually understand why the previous version worked on Windows
despite being incorrect, but I don't believe that explanation is of
interest for OP.

Re: Problem with calling C++ from Fortran

<udmvg7$11r4u$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1451&group=comp.lang.c%2B%2B#1451

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: dieterhansbritz@gmail.com (db)
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Mon, 11 Sep 2023 14:00:06 +0200
Organization: A noiseless patient Spider
Lines: 97
Message-ID: <udmvg7$11r4u$1@dont-email.me>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udkdu9$itm4$1@dont-email.me> <87o7iajh8b.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 11 Sep 2023 12:00:07 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="48ef5501f228d5629931eb778638341a";
logging-data="1109150"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19U1kMckwWDqR27q9lGXJDuuLhDOjHuQ8Q="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:rca+Hcx36F0cUoGU3NJ4xcd9Who=
Content-Language: en-US
In-Reply-To: <87o7iajh8b.fsf@bsb.me.uk>
 by: db - Mon, 11 Sep 2023 12:00 UTC

On 10.09.2023 15.22, Ben Bacarisse wrote:
> db <dieterhansbritz@gmail.com> writes:
>
>> On 09.09.2023 11.02, Muttley@dastardlyhq.com wrote:
>>> On Sat, 9 Sep 2023 10:54:33 +0200
>>> db <dieterhansbritz@gmail.com> wrote:
>>>> but now it says that C-double doesn't exist.
>>>>
>>>> Any ideas?
>>> C++ mangles function names so that the name you give the function isn't
>>> the
>>> name the dynamic loader sees in the binary. You need to put this around whatever
>>> function you want to call from Fortran so it has C style linkage which means
>>> the name remains the same:
>>> extern "C" {
>>> void calledFromFortran()
>>> {
>>> :
>>> }
>>> }
>>>
>> Where should this go in the code? I added it at the end as is,
>> and now I get this:
>>
>> ~/ownlib90/tests> ./jbandtest
>> jband.cpp:88:1: error: expected initializer before 'extern'
>> 88 | extern "C" {
>> | ^~~~~~
>> jband.cpp:96:1: error: expected unqualified-id before '{' token
>> 96 | {
>> | ^
>> jband.cpp: In function 'void calledFromFortran()':
>> jband.cpp:350:9: error: expected primary-expression before ':' token
>> 350 | :
>> ...
>
> You are giving people very little to go on. There's an unknown command
> (./jbandtest) the gives some errors where only one line of code can be
> seen.
>
> Can you produce a cut-down version to the program that shows the same
> error -- mimimal example of the C++ and of the Fortran that should
> calls it but which fails? That would mean you could post the code.
>
> If that is not possible, can you link to the source so those who know
> both C++ and Fortran can take a proper look?
>

I put the C++ function here: www.dieterbritz.dk/jband.cpp
After getting errors about the extern lines, whch I had
added at the end, I shifted it to near the start:

#include <iostream>
#include <fstream>
#include <iomanip>
#include "math.h"

using namespace std;

extern "C" {

void calledFromFortran()
{ :
}

}

....

I still get errors pertaining to these lines. But after adding
the -c to the two compilation lines in the script, these are
now the only errors. I think I am getting closer. The errors
are now

jband.cpp: In function 'void calledFromFortran()':
jband.cpp:12:9: error: expected primary-expression before ':' token
12 | :
| ^
jband.cpp: At global scope:
jband.cpp:96:1: error: expected initializer before 'extern'
96 | extern "C" {
| ^~~~~~
jband.cpp:104:1: error: expected unqualified-id before '{' token
104 | {
| ^
jbandtest.f90:28:14:

28 | FORTJBAND = JBAND (tbar)
| 1
Error: Type mismatch in argument 'tbar' at (1); passed REAL(16) to REAL(10)

The last error will go away together with the others.

--
Dieter Britz

Re: Problem with calling C++ from Fortran

<7dbe43e8-44b1-4147-86ce-002b4b68a6f4n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1452&group=comp.lang.c%2B%2B#1452

  copy link   Newsgroups: comp.lang.c++
X-Received: by 2002:a05:622a:12:b0:401:dfc4:6f8f with SMTP id x18-20020a05622a001200b00401dfc46f8fmr212474qtw.13.1694434878461;
Mon, 11 Sep 2023 05:21:18 -0700 (PDT)
X-Received: by 2002:a05:620a:2b45:b0:76d:9ab3:2e2c with SMTP id
dp5-20020a05620a2b4500b0076d9ab32e2cmr171916qkb.2.1694434878208; Mon, 11 Sep
2023 05:21:18 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c++
Date: Mon, 11 Sep 2023 05:21:18 -0700 (PDT)
In-Reply-To: <udmvg7$11r4u$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=199.203.251.52; posting-account=ow8VOgoAAAAfiGNvoH__Y4ADRwQF1hZW
NNTP-Posting-Host: 199.203.251.52
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udkdu9$itm4$1@dont-email.me> <87o7iajh8b.fsf@bsb.me.uk> <udmvg7$11r4u$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7dbe43e8-44b1-4147-86ce-002b4b68a6f4n@googlegroups.com>
Subject: Re: Problem with calling C++ from Fortran
From: already5chosen@yahoo.com (Michael S)
Injection-Date: Mon, 11 Sep 2023 12:21:18 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4787
 by: Michael S - Mon, 11 Sep 2023 12:21 UTC

On Monday, September 11, 2023 at 3:00:26 PM UTC+3, db wrote:
> On 10.09.2023 15.22, Ben Bacarisse wrote:
> > db <dieterh...@gmail.com> writes:
> >
> >> On 09.09.2023 11.02, Mut...@dastardlyhq.com wrote:
> >>> On Sat, 9 Sep 2023 10:54:33 +0200
> >>> db <dieterh...@gmail.com> wrote:
> >>>> but now it says that C-double doesn't exist.
> >>>>
> >>>> Any ideas?
> >>> C++ mangles function names so that the name you give the function isn't
> >>> the
> >>> name the dynamic loader sees in the binary. You need to put this around whatever
> >>> function you want to call from Fortran so it has C style linkage which means
> >>> the name remains the same:
> >>> extern "C" {
> >>> void calledFromFortran()
> >>> {
> >>> :
> >>> }
> >>> }
> >>>
> >> Where should this go in the code? I added it at the end as is,
> >> and now I get this:
> >>
> >> ~/ownlib90/tests> ./jbandtest
> >> jband.cpp:88:1: error: expected initializer before 'extern'
> >> 88 | extern "C" {
> >> | ^~~~~~
> >> jband.cpp:96:1: error: expected unqualified-id before '{' token
> >> 96 | {
> >> | ^
> >> jband.cpp: In function 'void calledFromFortran()':
> >> jband.cpp:350:9: error: expected primary-expression before ':' token
> >> 350 | :
> >> ...
> >
> > You are giving people very little to go on. There's an unknown command
> > (./jbandtest) the gives some errors where only one line of code can be
> > seen.
> >
> > Can you produce a cut-down version to the program that shows the same
> > error -- mimimal example of the C++ and of the Fortran that should
> > calls it but which fails? That would mean you could post the code.
> >
> > If that is not possible, can you link to the source so those who know
> > both C++ and Fortran can take a proper look?
> >
> I put the C++ function here: www.dieterbritz.dk/jband.cpp
> After getting errors about the extern lines, whch I had
> added at the end, I shifted it to near the start:
>
> #include <iostream>
> #include <fstream>
> #include <iomanip>
> #include "math.h"
>
> using namespace std;
>
> extern "C" {
>
> void calledFromFortran()
> {
> :
> }
>
> }
>
> ...
>
> I still get errors pertaining to these lines. But after adding
> the -c to the two compilation lines in the script, these are
> now the only errors. I think I am getting closer. The errors
> are now
> jband.cpp: In function 'void calledFromFortran()':
> jband.cpp:12:9: error: expected primary-expression before ':' token
> 12 | :
> | ^
> jband.cpp: At global scope:
> jband.cpp:96:1: error: expected initializer before 'extern'
> 96 | extern "C" {
> | ^~~~~~
> jband.cpp:104:1: error: expected unqualified-id before '{' token
> 104 | {
> | ^

You have got a special talent for messing up things. :(
Please, put the code as written by your C++ specialist on your web site.
As is, without modifications!
Then we can show you where to insert ' extern "C" '.

> jbandtest.f90:28:14:
>
> 28 | FORTJBAND = JBAND (tbar)
> | 1
> Error: Type mismatch in argument 'tbar' at (1); passed REAL(16) to REAL(10)
>

FORTJBAND = real(JBAND(Real(tbar, c_long_double)), dbl)

> The last error will go away together with the others.

>
> --
> Dieter Britz

Re: Problem with calling C++ from Fortran

<udn4ur$12ma9$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1453&group=comp.lang.c%2B%2B#1453

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Muttley@dastardlyhq.com
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Mon, 11 Sep 2023 13:33:15 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <udn4ur$12ma9$1@dont-email.me>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udkdu9$itm4$1@dont-email.me> <87o7iajh8b.fsf@bsb.me.uk>
<udmvg7$11r4u$1@dont-email.me>
Injection-Date: Mon, 11 Sep 2023 13:33:15 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="5fa00f5afe82d78c34565b5d5b1eaa90";
logging-data="1136969"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/bOz0lxZ9rTLOrEIlEhpz2"
Cancel-Lock: sha1:sD7u6eFSF9x58hINVtq+TdEAC/4=
 by: Muttley@dastardlyhq.com - Mon, 11 Sep 2023 13:33 UTC

On Mon, 11 Sep 2023 14:00:06 +0200
db <dieterhansbritz@gmail.com> wrote:
>jband.cpp: In function 'void calledFromFortran()':

I told you before that calledFromFortran() was simply an example function
name I chose. I could have called it deathToTurnips(). You need to use the
prototype of the function you're going to call.

>jband.cpp:12:9: error: expected primary-expression before ':' token
> 12 | :

FFS, that was just a space to indicate code goes there, its not C++ syntax!

You need to talk to your C++ guy, your knowledge of C/C++ is clearly
non existent so its pointless you trying to do something like this which can
have many gotchas beyond simple compilation.

Re: Problem with calling C++ from Fortran

<87cyyoqoka.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1460&group=comp.lang.c%2B%2B#1460

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Tue, 12 Sep 2023 00:26:29 +0100
Organization: A noiseless patient Spider
Lines: 223
Message-ID: <87cyyoqoka.fsf@bsb.me.uk>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udkdu9$itm4$1@dont-email.me> <87o7iajh8b.fsf@bsb.me.uk>
<udmvg7$11r4u$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="0b3d05af22d1f5f0f239039facdde43d";
logging-data="1309542"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3rb7t2kYp23G54TyeuSZkKAxUiWSwzmw="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:UnwTMd3o27ST4QkIsVGfP20WpMA=
sha1:5h0ZbHffTID4S+U2vAIJH5yWZts=
X-BSB-Auth: 1.21f8da5a1d0951939a1e.20230912002629BST.87cyyoqoka.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 11 Sep 2023 23:26 UTC

db <dieterhansbritz@gmail.com> writes:

> On 10.09.2023 15.22, Ben Bacarisse wrote:
>> db <dieterhansbritz@gmail.com> writes:
>>
>>> On 09.09.2023 11.02, Muttley@dastardlyhq.com wrote:
>>>> On Sat, 9 Sep 2023 10:54:33 +0200
>>>> db <dieterhansbritz@gmail.com> wrote:
>>>>> but now it says that C-double doesn't exist.
>>>>>
>>>>> Any ideas?
>>>> C++ mangles function names so that the name you give the function isn't
>>>> the
>>>> name the dynamic loader sees in the binary. You need to put this around whatever
>>>> function you want to call from Fortran so it has C style linkage which means
>>>> the name remains the same:
>>>> extern "C" {
>>>> void calledFromFortran()
>>>> {
>>>> :
>>>> }
>>>> }
>>>>
>>> Where should this go in the code? I added it at the end as is,
>>> and now I get this:
>>>
>>> ~/ownlib90/tests> ./jbandtest
>>> jband.cpp:88:1: error: expected initializer before 'extern'
>>> 88 | extern "C" {
>>> | ^~~~~~
>>> jband.cpp:96:1: error: expected unqualified-id before '{' token
>>> 96 | {
>>> | ^
>>> jband.cpp: In function 'void calledFromFortran()':
>>> jband.cpp:350:9: error: expected primary-expression before ':' token
>>> 350 | :
>>> ...
>> You are giving people very little to go on. There's an unknown command
>> (./jbandtest) the gives some errors where only one line of code can be
>> seen.
>> Can you produce a cut-down version to the program that shows the same
>> error -- mimimal example of the C++ and of the Fortran that should
>> calls it but which fails? That would mean you could post the code.
>> If that is not possible, can you link to the source so those who know
>> both C++ and Fortran can take a proper look?
>
> I put the C++ function here: www.dieterbritz.dk/jband.cpp
> After getting errors about the extern lines, whch I had
> added at the end, I shifted it to near the start:
>
> #include <iostream>
> #include <fstream>
> #include <iomanip>
> #include "math.h"
>
> using namespace std;
>
> extern "C" {
>
> void calledFromFortran()
> {
> :
> }
>
> }

Remove them all. You have two options. One: correct the C++. To do
this put this, and only this,

extern "C" {
const long double iband(const long double tbar);
}

just after the #include lines. This is perfect (the first const is a
meaningless word here and the compiler may warn you about that) but it
will do.

Next replace

#include "math.h"

with

#include <math.h>

I'd also remove the two unnecessary #include lines (for iomanip and
fstream). All of these are "tidying up". Only the extern "C" part I
gave corrects an actual mistake.

The second option is the turn the code in C which links directly with
Fortran. The only C++ used by the code is one "cout << " line (not a
good way to report an error, but that's not important right now) and a
setting for pi that is not a compile-time constant (4*atanl(1)) written
in a more fussy way.

To convert to C, copy the file to jband.c (rather than .cpp) and replce
the declaration for pi. Given the code is littered with explicit 21
digits decimals (a little more than the precision of C's usualy long
double type) I would just write

static const long double pi = 3.14159265358979323846L;

Now replace the cout line with

fputs("\nError in stredges::iband(): tbar must be > 0", stderr);

This writes the message to the error stream and put only these two
include lines at the top:

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

Now the file is C code.

Frankly, this is the way I'd go, since linking C is just that bit
simpler than linking C++. But if the code is going to become fully
fledged (and complex) C++, obviously use my first option.

> I still get errors pertaining to these lines. But after adding
> the -c to the two compilation lines in the script, these are
> now the only errors. I think I am getting closer. The errors
> are now

Yes, you must compile it like this:

g++ -c jband.cpp (for C++ code)
gcc -c jband.c (for C code)

You don't need any -o but you could add in lots of warnings like

gcc -Wall -Wextra -c jband.c

> jband.cpp: In function 'void calledFromFortran()':
> jband.cpp:12:9: error: expected primary-expression before ':' token
> 12 | :
> | ^
> jband.cpp: At global scope:
> jband.cpp:96:1: error: expected initializer before 'extern'
> 96 | extern "C" {
> | ^~~~~~
> jband.cpp:104:1: error: expected unqualified-id before '{' token
> 104 | {
> | ^
> jbandtest.f90:28:14:
>
> 28 | FORTJBAND = JBAND (tbar)
> | 1
> Error: Type mismatch in argument 'tbar' at (1); passed REAL(16) to REAL(10)
>
> The last error will go away together with the others.

Michael S has given you one way to go for that. My comments were going
to be more general. You have several ways of specifying the types, and
I could not tell if you really wanted all of them. In general, I would
define the Fortran types from the C ones (since those are the types you
need for the call and return) and leave it at that.

But the big one is that the Fortran code seems to think the function is
called jband, when in fact it's called iband.

I went for this:

module STUFF
use iso_c_binding
integer, parameter :: qud=real(c_long_double)
end module STUFF
program JBAND_TEST
use STUFF; implicit none
real(qud) :: tbar, curr, FORTJBAND
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 IBAND (tbar) bind(c)
use STUFF
real(qud), VALUE :: tbar
real(qud) :: IBAND
end function iband
end interface
real(qud) :: FORTJBAND, tbar
FORTJBAND = IBAND(tbar)
end function FORTJBAND

Note that you can compile the Fortran along with the C at the same time
if you like:

$ gfortran -o jtest jbandtest.f90 jband.c -lm
$ ./jtest
1 curr = 1.5224
1e-10
curr =56419.9584
-1
$

($ is my Linux command-line prompt). I have no idea if these are
correct results and I can't be sure what you need to run on your system,
but the code links and appears to work.

If you go with the C++ option, the linking needs the standard C++
library:

$ gfortran -o jtest jbandtest.f90 jband.cpp -lstdc++ -lm
$ ./jtest
1 curr = 1.5224
1e-10
curr =56419.9584
-1
$

BTW, you said the C++ was written by a C++ expert. I don't think it
was!

--
Ben.

Re: Problem with calling C++ from Fortran

<udp8l4$1frsv$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1464&group=comp.lang.c%2B%2B#1464

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: dieterhansbritz@gmail.com (db)
Newsgroups: comp.lang.c++
Subject: Re: Problem with calling C++ from Fortran
Date: Tue, 12 Sep 2023 10:48:36 +0200
Organization: A noiseless patient Spider
Lines: 233
Message-ID: <udp8l4$1frsv$1@dont-email.me>
References: <udhbs9$e5d$1@dont-email.me> <udhcaj$j8l$1@dont-email.me>
<udkdu9$itm4$1@dont-email.me> <87o7iajh8b.fsf@bsb.me.uk>
<udmvg7$11r4u$1@dont-email.me> <87cyyoqoka.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 12 Sep 2023 08:48:36 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a95eb3e5ffa1773c6f3000948b8740fd";
logging-data="1568671"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/cvnaedVKUGz09MGxbSB99TZMAz1+2FyI="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:PyQxj+B6BQ0toPHSHuO0tbwcrgs=
Content-Language: en-US
In-Reply-To: <87cyyoqoka.fsf@bsb.me.uk>
 by: db - Tue, 12 Sep 2023 08:48 UTC

On 12.09.2023 01.26, Ben Bacarisse wrote:
> db <dieterhansbritz@gmail.com> writes:
>
>> On 10.09.2023 15.22, Ben Bacarisse wrote:
>>> db <dieterhansbritz@gmail.com> writes:
>>>
>>>> On 09.09.2023 11.02, Muttley@dastardlyhq.com wrote:
>>>>> On Sat, 9 Sep 2023 10:54:33 +0200
>>>>> db <dieterhansbritz@gmail.com> wrote:
>>>>>> but now it says that C-double doesn't exist.
>>>>>>
>>>>>> Any ideas?
>>>>> C++ mangles function names so that the name you give the function isn't
>>>>> the
>>>>> name the dynamic loader sees in the binary. You need to put this around whatever
>>>>> function you want to call from Fortran so it has C style linkage which means
>>>>> the name remains the same:
>>>>> extern "C" {
>>>>> void calledFromFortran()
>>>>> {
>>>>> :
>>>>> }
>>>>> }
>>>>>
>>>> Where should this go in the code? I added it at the end as is,
>>>> and now I get this:
>>>>
>>>> ~/ownlib90/tests> ./jbandtest
>>>> jband.cpp:88:1: error: expected initializer before 'extern'
>>>> 88 | extern "C" {
>>>> | ^~~~~~
>>>> jband.cpp:96:1: error: expected unqualified-id before '{' token
>>>> 96 | {
>>>> | ^
>>>> jband.cpp: In function 'void calledFromFortran()':
>>>> jband.cpp:350:9: error: expected primary-expression before ':' token
>>>> 350 | :
>>>> ...
>>> You are giving people very little to go on. There's an unknown command
>>> (./jbandtest) the gives some errors where only one line of code can be
>>> seen.
>>> Can you produce a cut-down version to the program that shows the same
>>> error -- mimimal example of the C++ and of the Fortran that should
>>> calls it but which fails? That would mean you could post the code.
>>> If that is not possible, can you link to the source so those who know
>>> both C++ and Fortran can take a proper look?
>>
>> I put the C++ function here: www.dieterbritz.dk/jband.cpp
>> After getting errors about the extern lines, whch I had
>> added at the end, I shifted it to near the start:
>>
>> #include <iostream>
>> #include <fstream>
>> #include <iomanip>
>> #include "math.h"
>>
>> using namespace std;
>>
>> extern "C" {
>>
>> void calledFromFortran()
>> {
>> :
>> }
>>
>> }
>
> Remove them all. You have two options. One: correct the C++. To do
> this put this, and only this,
>
> extern "C" {
> const long double iband(const long double tbar);
> }
>
> just after the #include lines. This is perfect (the first const is a
> meaningless word here and the compiler may warn you about that) but it
> will do.
>
> Next replace
>
> #include "math.h"
>
> with
>
> #include <math.h>
>
> I'd also remove the two unnecessary #include lines (for iomanip and
> fstream). All of these are "tidying up". Only the extern "C" part I
> gave corrects an actual mistake.
>
> The second option is the turn the code in C which links directly with
> Fortran. The only C++ used by the code is one "cout << " line (not a
> good way to report an error, but that's not important right now) and a
> setting for pi that is not a compile-time constant (4*atanl(1)) written
> in a more fussy way.
>
> To convert to C, copy the file to jband.c (rather than .cpp) and replce
> the declaration for pi. Given the code is littered with explicit 21
> digits decimals (a little more than the precision of C's usualy long
> double type) I would just write
>
> static const long double pi = 3.14159265358979323846L;
>
> Now replace the cout line with
>
> fputs("\nError in stredges::iband(): tbar must be > 0", stderr);
>
> This writes the message to the error stream and put only these two
> include lines at the top:
>
> #include <math.h>
> #include <stdio.h>
>
> Now the file is C code.
>
> Frankly, this is the way I'd go, since linking C is just that bit
> simpler than linking C++. But if the code is going to become fully
> fledged (and complex) C++, obviously use my first option.
>
>> I still get errors pertaining to these lines. But after adding
>> the -c to the two compilation lines in the script, these are
>> now the only errors. I think I am getting closer. The errors
>> are now
>
> Yes, you must compile it like this:
>
> g++ -c jband.cpp (for C++ code)
> gcc -c jband.c (for C code)
>
> You don't need any -o but you could add in lots of warnings like
>
> gcc -Wall -Wextra -c jband.c
>
>> jband.cpp: In function 'void calledFromFortran()':
>> jband.cpp:12:9: error: expected primary-expression before ':' token
>> 12 | :
>> | ^
>> jband.cpp: At global scope:
>> jband.cpp:96:1: error: expected initializer before 'extern'
>> 96 | extern "C" {
>> | ^~~~~~
>> jband.cpp:104:1: error: expected unqualified-id before '{' token
>> 104 | {
>> | ^
>> jbandtest.f90:28:14:
>>
>> 28 | FORTJBAND = JBAND (tbar)
>> | 1
>> Error: Type mismatch in argument 'tbar' at (1); passed REAL(16) to REAL(10)
>>
>> The last error will go away together with the others.
>
> Michael S has given you one way to go for that. My comments were going
> to be more general. You have several ways of specifying the types, and
> I could not tell if you really wanted all of them. In general, I would
> define the Fortran types from the C ones (since those are the types you
> need for the call and return) and leave it at that.
>
> But the big one is that the Fortran code seems to think the function is
> called jband, when in fact it's called iband.
>
> I went for this:
>
> module STUFF
> use iso_c_binding
> integer, parameter :: qud=real(c_long_double)
> end module STUFF
> program JBAND_TEST
> use STUFF; implicit none
> real(qud) :: tbar, curr, FORTJBAND
> 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 IBAND (tbar) bind(c)
> use STUFF
> real(qud), VALUE :: tbar
> real(qud) :: IBAND
> end function iband
> end interface
> real(qud) :: FORTJBAND, tbar
> FORTJBAND = IBAND(tbar)
> end function FORTJBAND
>
> Note that you can compile the Fortran along with the C at the same time
> if you like:
>
> $ gfortran -o jtest jbandtest.f90 jband.c -lm
> $ ./jtest
> 1
> curr = 1.5224
> 1e-10
> curr =56419.9584
> -1
> $
>
> ($ is my Linux command-line prompt). I have no idea if these are
> correct results and I can't be sure what you need to run on your system,
> but the code links and appears to work.
>
> If you go with the C++ option, the linking needs the standard C++
> library:
>
> $ gfortran -o jtest jbandtest.f90 jband.cpp -lstdc++ -lm
> $ ./jtest
> 1
> curr = 1.5224
> 1e-10
> curr =56419.9584
> -1
> $
>
> BTW, you said the C++ was written by a C++ expert. I don't think it
> was!
>
The code, apart from the extra lines suggested by someone here,
but without the information on where to put them, is runnable
C++ code written by another person who knows C++ very well. I
myself use Fortran and you are right, I know next to nothing
about C++. I did use the extra code exactly as is, but possibly
put it in the wrong place. I tried two, without success.
I am giving up, and will translate the C++ function into Fortran,
where I know what I'm doing.
--
Dieter Britz


Click here to read the complete article
Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor