public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Linking c++ and fortran
@ 2000-03-07  9:14 Peter_Hahne
  2000-03-07 11:58 ` Martin v. Loewis
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Peter_Hahne @ 2000-03-07  9:14 UTC (permalink / raw)
  To: gcc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 931 bytes --]

Hello

I´m trying to call a fortran routine from a c++ routine
using gcc resp. g77/g++ , but dont get it to work.
Can somebody tell me how to do it?

Best regards, Peter


I tried
	g77 -o main main.cpp sub1.f -lstdc++  

and get the linker error message
 
	/tmp/ccK77Fls.o: In function `main':
	/tmp/ccK77Fls.o(.text+0x26): undefined reference to `sub1_(void)'
	collect2: ld returned 1 exit status

I am using

g77 version egcs-2.91.66 19990314 (egcs-1.1.2 release) (from FSF-g77 version 
0.5.24-19981002)

The sourcefiles are main.cpp

#include "iostream.h"
int sub1_();
main()
{
	cout << "main" << "\n";
	sub1_();
}

and sub1.f

      integer function sub1()
      sub1=0
      write (6,*) 'sub1'
      return
      end

----------------------------------------------------------------------
Dr.Peter Hahne, Zum Pitschgrund 7a, 64747 Breuberg Rai-Breitenbach,
Tel. +49 6165 912424, Fax +49 6165 912425, Mobile +49 171 5178749

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Linking c++ and fortran
  2000-03-07  9:14 Linking c++ and fortran Peter_Hahne
@ 2000-03-07 11:58 ` Martin v. Loewis
  2000-03-07 13:38   ` Peter_Hahne
  2000-04-01  0:00   ` Martin v. Loewis
  2000-03-07 12:01 ` Alexandre Oliva
  2000-04-01  0:00 ` Peter_Hahne
  2 siblings, 2 replies; 10+ messages in thread
From: Martin v. Loewis @ 2000-03-07 11:58 UTC (permalink / raw)
  To: Peter_Hahne; +Cc: gcc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 217 bytes --]

> I´m trying to call a fortran routine from a c++ routine
> using gcc resp. g77/g++ , but dont get it to work.
> Can somebody tell me how to do it?

You need to declare the external function as extern "C".

Martin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Linking c++ and fortran
  2000-03-07  9:14 Linking c++ and fortran Peter_Hahne
  2000-03-07 11:58 ` Martin v. Loewis
@ 2000-03-07 12:01 ` Alexandre Oliva
  2000-03-07 13:40   ` Peter_Hahne
  2000-04-01  0:00   ` Alexandre Oliva
  2000-04-01  0:00 ` Peter_Hahne
  2 siblings, 2 replies; 10+ messages in thread
From: Alexandre Oliva @ 2000-03-07 12:01 UTC (permalink / raw)
  To: Peter_Hahne; +Cc: gcc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 514 bytes --]

On Mar  7, 2000, Peter_Hahne@t-online.de (Peter_Hahne) wrote:

> I´m trying to call a fortran routine from a c++ routine

> int sub1_();

You should probably have declare it as `extern "C"', to avoid C++ name
mangling.

-- 
Alexandre Oliva     http://www.ic.unicamp.br/~oliva/     Enjoy Guaraná
Cygnus Solutions, a Red Hat company        aoliva@{redhat, cygnus}.com
Free Software Developer and Evangelist    CS PhD student at IC-Unicamp
oliva@{lsd.ic.unicamp.br, gnu.org}   Write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re:  Linking c++ and fortran
  2000-03-07 11:58 ` Martin v. Loewis
@ 2000-03-07 13:38   ` Peter_Hahne
  2000-04-01  0:00     ` Peter_Hahne
  2000-04-01  0:00   ` Martin v. Loewis
  1 sibling, 1 reply; 10+ messages in thread
From: Peter_Hahne @ 2000-03-07 13:38 UTC (permalink / raw)
  To: martin; +Cc: gcc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 475 bytes --]

Thanks a lot, that works

Martin v. Loewis schrieb:
> I´m trying to call a fortran routine from a c++ routine
> using gcc resp. g77/g++ , but dont get it to work.
> Can somebody tell me how to do it?

You need to declare the external function as extern "C".

Martin

----------------------------------------------------------------------
Dr.Peter Hahne, Zum Pitschgrund 7a, 64747 Breuberg Rai-Breitenbach,
Tel. +49 6165 912424, Fax +49 6165 912425, Mobile +49 171 5178749

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re:  Linking c++ and fortran
  2000-03-07 12:01 ` Alexandre Oliva
@ 2000-03-07 13:40   ` Peter_Hahne
  2000-04-01  0:00     ` Peter_Hahne
  2000-04-01  0:00   ` Alexandre Oliva
  1 sibling, 1 reply; 10+ messages in thread
From: Peter_Hahne @ 2000-03-07 13:40 UTC (permalink / raw)
  To: oliva; +Cc: gcc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 394 bytes --]

Thanks a lot, that works.


> I´m trying to call a fortran routine from a c++ routine

> int sub1_();

You should probably have declare it as `extern "C"', to avoid C++ name
mangling.


----------------------------------------------------------------------
Dr.Peter Hahne, Zum Pitschgrund 7a, 64747 Breuberg Rai-Breitenbach,
Tel. +49 6165 912424, Fax +49 6165 912425, Mobile +49 171 5178749

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Linking c++ and fortran
  2000-03-07 12:01 ` Alexandre Oliva
  2000-03-07 13:40   ` Peter_Hahne
@ 2000-04-01  0:00   ` Alexandre Oliva
  1 sibling, 0 replies; 10+ messages in thread
From: Alexandre Oliva @ 2000-04-01  0:00 UTC (permalink / raw)
  To: Peter_Hahne; +Cc: gcc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 514 bytes --]

On Mar  7, 2000, Peter_Hahne@t-online.de (Peter_Hahne) wrote:

> I´m trying to call a fortran routine from a c++ routine

> int sub1_();

You should probably have declare it as `extern "C"', to avoid C++ name
mangling.

-- 
Alexandre Oliva     http://www.ic.unicamp.br/~oliva/     Enjoy Guaraná
Cygnus Solutions, a Red Hat company        aoliva@{redhat, cygnus}.com
Free Software Developer and Evangelist    CS PhD student at IC-Unicamp
oliva@{lsd.ic.unicamp.br, gnu.org}   Write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re:  Linking c++ and fortran
  2000-03-07 13:38   ` Peter_Hahne
@ 2000-04-01  0:00     ` Peter_Hahne
  0 siblings, 0 replies; 10+ messages in thread
From: Peter_Hahne @ 2000-04-01  0:00 UTC (permalink / raw)
  To: martin; +Cc: gcc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 475 bytes --]

Thanks a lot, that works

Martin v. Loewis schrieb:
> I´m trying to call a fortran routine from a c++ routine
> using gcc resp. g77/g++ , but dont get it to work.
> Can somebody tell me how to do it?

You need to declare the external function as extern "C".

Martin

----------------------------------------------------------------------
Dr.Peter Hahne, Zum Pitschgrund 7a, 64747 Breuberg Rai-Breitenbach,
Tel. +49 6165 912424, Fax +49 6165 912425, Mobile +49 171 5178749

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Linking c++ and fortran
  2000-03-07  9:14 Linking c++ and fortran Peter_Hahne
  2000-03-07 11:58 ` Martin v. Loewis
  2000-03-07 12:01 ` Alexandre Oliva
@ 2000-04-01  0:00 ` Peter_Hahne
  2 siblings, 0 replies; 10+ messages in thread
From: Peter_Hahne @ 2000-04-01  0:00 UTC (permalink / raw)
  To: gcc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 931 bytes --]

Hello

I´m trying to call a fortran routine from a c++ routine
using gcc resp. g77/g++ , but dont get it to work.
Can somebody tell me how to do it?

Best regards, Peter


I tried
	g77 -o main main.cpp sub1.f -lstdc++  

and get the linker error message
 
	/tmp/ccK77Fls.o: In function `main':
	/tmp/ccK77Fls.o(.text+0x26): undefined reference to `sub1_(void)'
	collect2: ld returned 1 exit status

I am using

g77 version egcs-2.91.66 19990314 (egcs-1.1.2 release) (from FSF-g77 version 
0.5.24-19981002)

The sourcefiles are main.cpp

#include "iostream.h"
int sub1_();
main()
{
	cout << "main" << "\n";
	sub1_();
}

and sub1.f

      integer function sub1()
      sub1=0
      write (6,*) 'sub1'
      return
      end

----------------------------------------------------------------------
Dr.Peter Hahne, Zum Pitschgrund 7a, 64747 Breuberg Rai-Breitenbach,
Tel. +49 6165 912424, Fax +49 6165 912425, Mobile +49 171 5178749

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Linking c++ and fortran
  2000-03-07 11:58 ` Martin v. Loewis
  2000-03-07 13:38   ` Peter_Hahne
@ 2000-04-01  0:00   ` Martin v. Loewis
  1 sibling, 0 replies; 10+ messages in thread
From: Martin v. Loewis @ 2000-04-01  0:00 UTC (permalink / raw)
  To: Peter_Hahne; +Cc: gcc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 217 bytes --]

> I´m trying to call a fortran routine from a c++ routine
> using gcc resp. g77/g++ , but dont get it to work.
> Can somebody tell me how to do it?

You need to declare the external function as extern "C".

Martin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re:  Linking c++ and fortran
  2000-03-07 13:40   ` Peter_Hahne
@ 2000-04-01  0:00     ` Peter_Hahne
  0 siblings, 0 replies; 10+ messages in thread
From: Peter_Hahne @ 2000-04-01  0:00 UTC (permalink / raw)
  To: oliva; +Cc: gcc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 394 bytes --]

Thanks a lot, that works.


> I´m trying to call a fortran routine from a c++ routine

> int sub1_();

You should probably have declare it as `extern "C"', to avoid C++ name
mangling.


----------------------------------------------------------------------
Dr.Peter Hahne, Zum Pitschgrund 7a, 64747 Breuberg Rai-Breitenbach,
Tel. +49 6165 912424, Fax +49 6165 912425, Mobile +49 171 5178749

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2000-04-01  0:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-07  9:14 Linking c++ and fortran Peter_Hahne
2000-03-07 11:58 ` Martin v. Loewis
2000-03-07 13:38   ` Peter_Hahne
2000-04-01  0:00     ` Peter_Hahne
2000-04-01  0:00   ` Martin v. Loewis
2000-03-07 12:01 ` Alexandre Oliva
2000-03-07 13:40   ` Peter_Hahne
2000-04-01  0:00     ` Peter_Hahne
2000-04-01  0:00   ` Alexandre Oliva
2000-04-01  0:00 ` Peter_Hahne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).