Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #91612 > unrolled thread
| Started by | db <dieterhansbritz@gmail.com> |
|---|---|
| First post | 2023-09-09 10:54 +0200 |
| Last post | 2023-09-11 05:14 -0700 |
| Articles | 20 on this page of 33 — 9 participants |
Back to article view | Back to comp.lang.c++
Problem with calling C++ from Fortran db <dieterhansbritz@gmail.com> - 2023-09-09 10:54 +0200
Re: Problem with calling C++ from Fortran Muttley@dastardlyhq.com - 2023-09-09 09:02 +0000
Re: Problem with calling C++ from Fortran db <dieterhansbritz@gmail.com> - 2023-09-09 12:47 +0200
Re: Problem with calling C++ from Fortran Muttley@dastardlyhq.com - 2023-09-09 10:51 +0000
Re: Problem with calling C++ from Fortran db <dieterhansbritz@gmail.com> - 2023-09-09 12:52 +0200
Re: Problem with calling C++ from Fortran Muttley@dastardlyhq.com - 2023-09-09 11:00 +0000
Re: Problem with calling C++ from Fortran db <dieterhansbritz@gmail.com> - 2023-09-10 14:33 +0200
Re: Problem with calling C++ from Fortran Paavo Helde <eesnimi@osa.pri.ee> - 2023-09-10 18:49 +0300
Re: Problem with calling C++ from Fortran Muttley@dastardlyhq.com - 2023-09-11 08:23 +0000
Re: Problem with calling C++ from Fortran Paavo Helde <eesnimi@osa.pri.ee> - 2023-09-09 16:56 +0300
Re: Problem with calling C++ from Fortran db <dieterhansbritz@gmail.com> - 2023-09-10 14:36 +0200
Re: Problem with calling C++ from Fortran James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-09-11 00:14 -0400
Re: Problem with calling C++ from Fortran Bo Persson <bo@bo-persson.se> - 2023-09-10 16:08 +0200
Re: Problem with calling C++ from Fortran "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-09-09 16:30 +0200
Re: Problem with calling C++ from Fortran db <dieterhansbritz@gmail.com> - 2023-09-10 14:48 +0200
Re: Problem with calling C++ from Fortran Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-09-10 14:22 +0100
Re: Problem with calling C++ from Fortran Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-09-10 17:27 +0100
Re: Problem with calling C++ from Fortran db <dieterhansbritz@gmail.com> - 2023-09-11 14:00 +0200
Re: Problem with calling C++ from Fortran Michael S <already5chosen@yahoo.com> - 2023-09-11 05:21 -0700
Re: Problem with calling C++ from Fortran Muttley@dastardlyhq.com - 2023-09-11 13:33 +0000
Re: Problem with calling C++ from Fortran Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-09-12 00:26 +0100
Re: Problem with calling C++ from Fortran db <dieterhansbritz@gmail.com> - 2023-09-12 10:48 +0200
Re: Problem with calling C++ from Fortran Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-09-12 14:14 +0100
Re: Problem with calling C++ from Fortran Michael S <already5chosen@yahoo.com> - 2023-09-12 07:15 -0700
Re: Problem with calling C++ from Fortran Michael S <already5chosen@yahoo.com> - 2023-09-12 02:00 -0700
Re: Problem with calling C++ from Fortran Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-09-12 14:22 +0100
Re: Problem with calling C++ from Fortran Michael S <already5chosen@yahoo.com> - 2023-09-12 07:32 -0700
Re: Problem with calling C++ from Fortran db <dieterhansbritz@gmail.com> - 2023-09-12 18:36 +0200
Re: Problem with calling C++ from Fortran Michael S <already5chosen@yahoo.com> - 2023-09-19 02:39 -0700
Re: Problem with calling C++ from Fortran Michael S <already5chosen@yahoo.com> - 2023-09-10 08:38 -0700
Re: Problem with calling C++ from Fortran Michael S <already5chosen@yahoo.com> - 2023-09-10 09:51 -0700
Re: Problem with calling C++ from Fortran Michael S <already5chosen@yahoo.com> - 2023-09-11 02:49 -0700
Buy Zen Mushroom Chocolate Bar Microdose "https://psychedelicminds.shop/" <psychedelicsmind@gmail.com> - 2023-09-11 05:14 -0700
Page 1 of 2 [1] 2 Next page →
| From | db <dieterhansbritz@gmail.com> |
|---|---|
| Date | 2023-09-09 10:54 +0200 |
| Subject | Problem with calling C++ from Fortran |
| Message-ID | <udhbs9$e5d$1@dont-email.me> |
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
[toc] | [next] | [standalone]
| From | Muttley@dastardlyhq.com |
|---|---|
| Date | 2023-09-09 09:02 +0000 |
| Message-ID | <udhcaj$j8l$1@dont-email.me> |
| In reply to | #91612 |
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()
{
:
}
}
[toc] | [prev] | [next] | [standalone]
| From | db <dieterhansbritz@gmail.com> |
|---|---|
| Date | 2023-09-09 12:47 +0200 |
| Message-ID | <udhigb$1n4d$1@dont-email.me> |
| In reply to | #91613 |
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
[toc] | [prev] | [next] | [standalone]
| From | Muttley@dastardlyhq.com |
|---|---|
| Date | 2023-09-09 10:51 +0000 |
| Message-ID | <udhio7$1o70$1@dont-email.me> |
| In reply to | #91614 |
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.
[toc] | [prev] | [next] | [standalone]
| From | db <dieterhansbritz@gmail.com> |
|---|---|
| Date | 2023-09-09 12:52 +0200 |
| Message-ID | <udhipr$1o3a$1@dont-email.me> |
| In reply to | #91614 |
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
[toc] | [prev] | [next] | [standalone]
| From | Muttley@dastardlyhq.com |
|---|---|
| Date | 2023-09-09 11:00 +0000 |
| Message-ID | <udhj7o$1qkq$1@dont-email.me> |
| In reply to | #91616 |
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.
[toc] | [prev] | [next] | [standalone]
| From | db <dieterhansbritz@gmail.com> |
|---|---|
| Date | 2023-09-10 14:33 +0200 |
| Message-ID | <udkd2m$iokr$1@dont-email.me> |
| In reply to | #91617 |
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
[toc] | [prev] | [next] | [standalone]
| From | Paavo Helde <eesnimi@osa.pri.ee> |
|---|---|
| Date | 2023-09-10 18:49 +0300 |
| Message-ID | <udkohd$kf94$1@dont-email.me> |
| In reply to | #91645 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Muttley@dastardlyhq.com |
|---|---|
| Date | 2023-09-11 08:23 +0000 |
| Message-ID | <udmipr$vtg5$1@dont-email.me> |
| In reply to | #91645 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Paavo Helde <eesnimi@osa.pri.ee> |
|---|---|
| Date | 2023-09-09 16:56 +0300 |
| Message-ID | <udhthr$3dir$1@dont-email.me> |
| In reply to | #91616 |
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.
[toc] | [prev] | [next] | [standalone]
| From | db <dieterhansbritz@gmail.com> |
|---|---|
| Date | 2023-09-10 14:36 +0200 |
| Message-ID | <udkd83$iokr$2@dont-email.me> |
| In reply to | #91618 |
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
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@alumni.caltech.edu> |
|---|---|
| Date | 2023-09-11 00:14 -0400 |
| Message-ID | <udm475$u0mo$1@dont-email.me> |
| In reply to | #91618 |
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?
[toc] | [prev] | [next] | [standalone]
| From | Bo Persson <bo@bo-persson.se> |
|---|---|
| Date | 2023-09-10 16:08 +0200 |
| Message-ID | <km60u6Floj6U1@mid.individual.net> |
| In reply to | #91616 |
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.
[toc] | [prev] | [next] | [standalone]
| From | "Alf P. Steinbach" <alf.p.steinbach@gmail.com> |
|---|---|
| Date | 2023-09-09 16:30 +0200 |
| Message-ID | <udhvia$41ae$1@dont-email.me> |
| In reply to | #91614 |
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 } ?
[toc] | [prev] | [next] | [standalone]
| From | db <dieterhansbritz@gmail.com> |
|---|---|
| Date | 2023-09-10 14:48 +0200 |
| Message-ID | <udkdu9$itm4$1@dont-email.me> |
| In reply to | #91613 |
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
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2023-09-10 14:22 +0100 |
| Message-ID | <87o7iajh8b.fsf@bsb.me.uk> |
| In reply to | #91647 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2023-09-10 17:27 +0100 |
| Message-ID | <87il8ij8n5.fsf@bsb.me.uk> |
| In reply to | #91648 |
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.
[toc] | [prev] | [next] | [standalone]
| From | db <dieterhansbritz@gmail.com> |
|---|---|
| Date | 2023-09-11 14:00 +0200 |
| Message-ID | <udmvg7$11r4u$1@dont-email.me> |
| In reply to | #91648 |
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
[toc] | [prev] | [next] | [standalone]
| From | Michael S <already5chosen@yahoo.com> |
|---|---|
| Date | 2023-09-11 05:21 -0700 |
| Message-ID | <7dbe43e8-44b1-4147-86ce-002b4b68a6f4n@googlegroups.com> |
| In reply to | #91683 |
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
[toc] | [prev] | [next] | [standalone]
| From | Muttley@dastardlyhq.com |
|---|---|
| Date | 2023-09-11 13:33 +0000 |
| Message-ID | <udn4ur$12ma9$1@dont-email.me> |
| In reply to | #91683 |
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.
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.c++
csiph-web