| 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.
.
|
|
|
|

|
Related Articles |
|
|