本帖最后由 安靖 于 2014-11-19 16:54 编辑  
 
自己搞定了,改成这样就行了。。 
 
c++文件 
sum.cpp 
[] syntaxhighlighter_viewsource syntaxhighlighter_copycode #indef __cplusplus
      extern "C"{
      int sum_fun_(int &, double *, double &);
}#endif
int sum_fun_(int &n, double num[], double &sum)
{
       int i;
       sum = 0.0;
       for(i = 0; i < n; i++)
       { 
               sum += num;
        }
        return 0;
} 
fortran文件 
main.f90 
[Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode program main
     implicit none
     integer :: n
     real :: a
     real, allocatable, dimension(:) :: num
     n = 4
     allocate( num(n) )
    num = 1.0;
    call sum_fun(n, num, a)
     write(*,*) "The sum is ', a
end program 
 
cpp生成静态库 
g++ -c sum.cpp 
ar -cr libsum.a sum.o 
生成可执行程序 
ifort -c -r8 -main.f90 
ifort -o test main.o -L./ -lsum -lstdc++ 
 
 
 
 |