 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Dennis Kernighan Guest
|
Posted: Fri Mar 05, 2004 8:41 am Post subject: 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
|
|
| Back to top |
|
 |
Jeff Schwab Guest
|
Posted: Fri Mar 05, 2004 8:48 am Post subject: Re: Fortran call from C++ |
|
|
Dennis Kernighan wrote:
| Quote: | 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.
|
|
| Back to top |
|
 |
Charles LaCour Guest
|
Posted: Fri Mar 05, 2004 9:39 pm Post subject: Re: Fortran call from C++ |
|
|
"Dennis Kernighan" <kernighan (AT) australia (DOT) edu> wrote
| Quote: | 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.
| Quote: |
------- 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
|
|
|
| Back to top |
|
 |
Gianni Mariani Guest
|
Posted: Fri Mar 05, 2004 9:54 pm Post subject: Re: Fortran call from C++ |
|
|
Dennis Kernighan wrote:
| Quote: | 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.
| Quote: | 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
| Quote: | 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: %dn", FACT(7));
PYTHAGORAS (30, 40, &c);
std::printf("Hypotenuse if sides 30, 40 is: %fn", c);
}
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|