C++ and Fortran - Help linking files
C++ and Fortran - Help linking files
- Subject: C++ and Fortran - Help linking files
- From: David Bourne <email@hidden>
- Date: Fri, 11 Nov 2016 14:49:17 -0700
Hi
I have some long time Fortran code that I would like to use in a Swift project ;-) My plan is to link fortran code to C++ code and bridge to Swift code. I’ve been able to add C code to a Swift app so that part should be doable.
I notice that Xcode Project Targets > Build Rules include Custom Scripts which include Process: Fortran source files Using: option.
The default compiler doesn’t work but I was able to include gfortran in the mix.
Project Targets > Build Rules I added Process Fortran source files Using Custom Script gfortran
also Project Targets > Build Phases I added a New Run Script
Shell /bin/sh
1 gfortran $(SRCROOT)example4/example.f $(SRCROOT)example4/other.f
>>> example.f
write(6,10)
10 format("Hello from Fortran")
call outText()
call otherText()
end
subroutine outText()
write(*,10)
10 format("Inside the subroutine")
return
end
>>> other.f
subroutine otherText()
write(6,10)
10 format("Inside other text subroutine")
return
end
Build succeeds but gives a message that it can’t launch example4. OK, I changed the target to executable a.out and it now runs in the console.
--
Moving to combining C++ and fortran. That is calling Fortran code from C++
I used the example in http://www.neurophys.wisc.edu/comp/docs/not017/
With
extern "C"
{
void FR1(int *, int *);
int FF1(int *);
}
I get the error messages
Undefined symbols for architecture x86_64:
"_FF1", referenced from:
_main in main.o
"_FR1", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Adding underscores doesn’t help. It just adds the underscores to error message. If the subroutine and functions names don’t match the editor complains.
(BTW I havdn’t found where to add the -v)
I’ve looked everywhere I can think of without success. I was thinking it was a fortran problem but it now looks like a linker issue.
It looks like a linker problem. From some reading it might need to use gfortran or gcc to link the c++ and fortran object files??
Any suggestions?
Thanks, David
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden