CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Main CFD Forum

command to link fortran and c object

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   May 4, 2001, 15:53
Default command to link fortran and c object
  #1
phuang
Guest
 
Posts: n/a
Please help me what is the command in PC to link fortran and c object to create an executive file. I have a program written in fortran and c.
  Reply With Quote

Old   May 4, 2001, 17:22
Default Re: command to link fortran and c object
  #2
andy
Guest
 
Posts: n/a
The program that performs the operation is usually called a linker. On unix the command is "ld". It used to be "link" on PCDOS many years ago but I do not know how to perform the task by pointing and clicking at windows these days.

In addition, you will have to make sure all the Fortran and C libraries are linked in, the Fortran calling C and vice-versa naming conventions are followed (usually by adding underscores) and the convention for passing Fortran strings is followed (Fortran passes a pointer and a length, C just the pointer - usually the lengths are collected in order and placed at the end of the argument list). Mixed I/O can be a problem on some systems. Some systems prefer main to be in Fortran while others in C. The task is not wholly straightforward the first time and varies from system to system.

  Reply With Quote

Old   May 4, 2001, 23:47
Default Re: command to link fortran and c object
  #3
clifford bradford
Guest
 
Posts: n/a
Yeah it's a pain in the ass. I had to do this once for visual C they recomended compiling individually then linking w/ visual C.
  Reply With Quote

Old   May 5, 2001, 03:27
Default Re: command to link fortran and c object
  #4
D.M. Lipinski
Guest
 
Posts: n/a
To be able to link Fortran and C, watch the following rules during compilation. 1. For Fortran sources: use compiler switch to add underscore to all external names. 2. For Fortran sources: use compile switch to generate all external names in lowercase. 3. Make sure that you pass arguments by reference (pointers) between C and Fortran. 4. Avoid passing character strings between Fortran and C. If you must do it, read the documentation on how your compilers pass (and expect) characters in the parameter list. Besides the character string, its length should often be specified.

Now you can link the object files with the linker.

DML
  Reply With Quote

Old   May 5, 2001, 21:22
Default Re: command to link fortran and c object
  #5
John C. Chien
Guest
 
Posts: n/a
(1). I had looked into this kind of mixed language programming long time ago. But my conclusion was, try to avoid it by all means.
  Reply With Quote

Old   May 10, 2001, 06:06
Default Re: command to link fortran and c object
  #6
Kike
Guest
 
Posts: n/a
Dear PHuang

After you had read all the messages in this thread try this

(1) to compile your C source

cc -c c_source.c

(2) to link it with your fortran code

f77 f_source.f c_source.o

I agree with JCChien, avoid this

Best whishes

Kike
  Reply With Quote

Old   May 17, 2001, 15:47
Default Re: command to link fortran and c object
  #7
phuang
Guest
 
Posts: n/a
I can not avoid link c with fortran, because some cfd softwares are written in fortran and c. Normally they are linked by makefile in SGI. Can we create makefile for PC?
  Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to link Fortran to Star-CD lunar1984 CD-adapco 0 September 13, 2011 10:16
How to link Fortran to Star-CD lunar1984 STAR-CD 0 September 13, 2011 10:02
CFX11 + Fortran compiler ? Mohan CFX 20 March 30, 2011 18:56
How to link my fortran program to UDFs? Sam FLUENT 0 October 29, 2008 04:57
link c++ with fortran object Pao Main CFD Forum 0 July 17, 2002 17:51


All times are GMT -4. The time now is 11:23.