public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Calling C from Fortran
@ 2011-05-30 22:42 coml2
  2011-05-31  5:44 ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: coml2 @ 2011-05-30 22:42 UTC (permalink / raw)
  To: gcc-help

I am using an iMac running 10.6.7.

I have a simple Fortran program that uses a simple C function and am working at the command line in Terminal.

I compile the C function with:

gcc -c createfile_.c

I then compile and link with:

gfortran test_file_handling.f90 createfile_.o

And get the error message:

ld: warning: in createfile_.o, file was built for unsupported file format which is not the architecture being linked (i386)
Undefined symbols:
  "_createfile_", referenced from:
      _MAIN__ in cc1JcwIf.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

I then tried to define the architecture with:

gcc -c -mtune=i386 createfile_.c

and got the error message:

createfile_.c:1: error: CPU you selected does not support x86-64 instruction set

I tried other values of -mtune but have been unsuccessful.  I have searched help forums and Googled but have not found answers that seem applicable.

Please advise me regarding how to compile and link for using C functions in gfortran.
 
Hugh McCutchen
coml2@san.rr.com


Note:  gcc is a link that points to gcc-4.2 dated October 23, 2010.
Note:  I have appended an underscore to the C function name.

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

* Re: Calling C from Fortran
  2011-05-30 22:42 Calling C from Fortran coml2
@ 2011-05-31  5:44 ` Jonathan Wakely
  2011-05-31  5:46   ` coml2
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2011-05-31  5:44 UTC (permalink / raw)
  To: coml2, gcc-help

-mtune doesn't change the target architecture, you need -m32 to
produce 32-bit output

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

* Re: Calling C from Fortran
  2011-05-31  5:44 ` Jonathan Wakely
@ 2011-05-31  5:46   ` coml2
  0 siblings, 0 replies; 4+ messages in thread
From: coml2 @ 2011-05-31  5:46 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

Jonathan,

Thanks for your prompt reply that was clear and works.

Hugh


On May 30, 2011, at 3:00 PM, Jonathan Wakely wrote:

-mtune doesn't change the target architecture, you need -m32 to
produce 32-bit output

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

* calling c++ from fortran
@ 2007-07-09 19:17 Dima Sorkin
  0 siblings, 0 replies; 4+ messages in thread
From: Dima Sorkin @ 2007-07-09 19:17 UTC (permalink / raw)
  To: gcc-help

Hi.
 I have a library written on Fortran 90, it does some calculations
with the user provided function

INTEGER, PARAMETER :: DP = SELECTED_REAL_KIND(15,70)

SUBROUTINE FDF(Z,F,DF)

COMPLEX(KIND=DP), INTENT(IN) :: Z
COMPLEX(KIND=DP), INTENT(OUT) :: F, DF
...

I want to wrap a call to a c++ function

// 'fcc.hpp'
extern "C"
void fcc(complex<double> z, complex<double> &f, complex<double> &df);

inside 'SUBROUTINE FDF'.
How do I do it, and how do I then link the fortran module with
the c++'s  object file 'fcc.o' ?

-- All compilations are done by GCC (or the 4.1.2 g++ and gfortran pair is used,
  or  the 3.4 g++ and g77 )
-- c++ runtime is properly initialized, as the program starts in c++, then calls
   fortran which then wants to call c++.

Thank you.
 Dima.

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

end of thread, other threads:[~2011-05-30 22:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-30 22:42 Calling C from Fortran coml2
2011-05-31  5:44 ` Jonathan Wakely
2011-05-31  5:46   ` coml2
  -- strict thread matches above, loose matches on Subject: below --
2007-07-09 19:17 calling c++ from fortran Dima Sorkin

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