C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Fortran call from C++

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Dennis Kernighan
Guest





PostPosted: Fri Mar 05, 2004 8:41 am    Post subject: Fortran call from C++ Reply with 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
Back to top
Jeff Schwab
Guest





PostPosted: Fri Mar 05, 2004 8:48 am    Post subject: Re: Fortran call from C++ Reply with quote



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





PostPosted: Fri Mar 05, 2004 9:39 pm    Post subject: Re: Fortran call from C++ Reply with quote




"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





PostPosted: Fri Mar 05, 2004 9:54 pm    Post subject: Re: Fortran call from C++ Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.