Fortran call from C++



 DEVELOP > c-Plus-Plus > Fortran call from C++

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Dennis Kernighan"
Date: 05 Mar 2004 02:41:53 AM
Object: Fortran call from C++
On Microsoft's pages there is an example of making Fortran call from
C++, see http://tinyurl.com/2692f . If I put C code in the test.c and
Fortran code in FORSUBS.FOR and press F5 in C++, I get following
errors:
------- error statement --------

fortrantester error LNK2019: unresolved external symbol "void
__stdcall
PYTHAGORAS(float,float,float *)" (?PYTHAGORAS@@YGXMMPAM@Z) referenced
in
function _main

fortrantester error LNK2019: unresolved external symbol "int __stdcall
FACT(int)" (?FACT@@YGHH@Z) referenced in function _main

fortrantester fatal error LNK1120: 2 unresolved externals

------- error statement --------
So. Is the problem that Fortran compiler is missing? Where could I get
one and how will I tell to C++ that it should use it?
DK
.

User: "Charles LaCour"

Title: Re: Fortran call from C++ 05 Mar 2004 03:39:23 PM
"Dennis Kernighan" <kernighan@australia.edu> wrote in message
news:e01abda9.0403050041.beec3ab@posting.google.com...

On Microsoft's pages there is an example of making Fortran call from
C++, see http://tinyurl.com/2692f . If I put C code in the test.c and
Fortran code in FORSUBS.FOR and press F5 in C++, I get following
errors:

Posting some a small executable source file wouldn't hurt.


------- error statement --------

fortrantester error LNK2019: unresolved external symbol "void
__stdcall
PYTHAGORAS(float,float,float *)" (?PYTHAGORAS@@YGXMMPAM@Z) referenced
in
function _main

fortrantester error LNK2019: unresolved external symbol "int __stdcall
FACT(int)" (?FACT@@YGHH@Z) referenced in function _main

fortrantester fatal error LNK1120: 2 unresolved externals

------- error statement --------

So. Is the problem that Fortran compiler is missing? Where could I get
one and how will I tell to C++ that it should use it?

DK

.

User: "Gianni Mariani"

Title: Re: Fortran call from C++ 05 Mar 2004 03:54:18 PM
Dennis Kernighan wrote:

On Microsoft's pages there is an example of making Fortran call from
C++, see http://tinyurl.com/2692f . If I put C code in the test.c and
Fortran code in FORSUBS.FOR and press F5 in C++, I get following
errors:

------- error statement --------

fortrantester error LNK2019: unresolved external symbol "void
__stdcall
PYTHAGORAS(float,float,float *)" (?PYTHAGORAS@@YGXMMPAM@Z) referenced
in

The symbol here "?PYTHAGORAS@@YGXMMPAM@Z" is a C++ mangled name. There
is a standard way to tell the C++ compiler to not use "external linkage"
- this is by using the ' extern "C" ' syntax. See below.

function _main

fortrantester error LNK2019: unresolved external symbol "int __stdcall
FACT(int)" (?FACT@@YGHH@Z) referenced in function _main

fortrantester fatal error LNK1120: 2 unresolved externals

------- error statement --------

So. Is the problem that Fortran compiler is missing?

You'll obciously need fortran libraries, but you don't need a fortran
compiler to link with a fortran library.
Where could I get

one and how will I tell to C++ that it should use it?

... I'll let you figure this out ..
The right way to do this using C++ is below:
#include <cstdio>
extern "C"
{
extern int FACT (int n);
extern void PYTHAGORAS (float a, float b, float *c);
};
main()
{
float c;
std::printf("Factorial of 7 is: %d\n", FACT(7));
PYTHAGORAS (30, 40, &c);
std::printf("Hypotenuse if sides 30, 40 is: %f\n", c);
}
.

User: "Jeff Schwab"

Title: Re: Fortran call from C++ 05 Mar 2004 02:48:57 AM
Dennis Kernighan wrote:

On Microsoft's pages there is an example of making Fortran call from
C++, see http://tinyurl.com/2692f . If I put C code in the test.c and
Fortran code in FORSUBS.FOR and press F5 in C++, I get following
errors:

------- error statement --------

fortrantester error LNK2019: unresolved external symbol "void
__stdcall
PYTHAGORAS(float,float,float *)" (?PYTHAGORAS@@YGXMMPAM@Z) referenced
in
function _main

fortrantester error LNK2019: unresolved external symbol "int __stdcall
FACT(int)" (?FACT@@YGHH@Z) referenced in function _main

fortrantester fatal error LNK1120: 2 unresolved externals

------- error statement --------

So. Is the problem that Fortran compiler is missing? Where could I get
one and how will I tell to C++ that it should use it?

DK

Wel,, Dennis Kernighan, I don't think the C++ standard attaches any
particular, Fortran-related behavior to the pressing of F5... I think
you need to try one of the MS support groups, or perhaps even read your
linker's documentation.
.


  Page 1 of 1

1

 


Related Articles
How to call Fortran moules from C++?
Many Fortran code! How to call Fortran code from C/C++?
Re: How can a constructor call another contructor?
Is this right? Can't call protected member of base class from derivedclass method, for another object
Microsoft runtime error R6025 Pure Virtual Function Call: a technicalreport
how to call an external program?
ECOOP 2004 - Call for Participation
any tricks to help us from forgetting to call test functions?
Is it legal to call functions in the initializer list?
Announce: C++ Connections Call For Papers
How can I call an enclosing class's function?
Need to call mixed-mode dll from native code.
How to Call Templatise function of class
How can I call class member function by a globle function pointer?
is it okay to call the overrided assignment function in copy constructor
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER