编译错误:找不到“_for_stop_core”

时间:2013-10-14 15:38:12

标签: compiler-errors fortran icc intel-fortran fortran-iso-c-binding

我正在尝试编译一个调用fortran子例程的c代码,但我总是得到错误。

这是fortran代码:

!fort_sub.f90
module myadd
use iso_c_binding
implicit none
contains

subroutine add1(a) bind(c)
implicit none
integer (c_int),intent (inout) :: a
a=a+1

if(a>10) then
   stop
endif
end subroutine add1
end module myadd

这是c代码

//main.cpp
extern "C"{ void add1(int * a); }

int main(void){
  int a=2;
  add1(&a);
  return 0;
}

当我用

编译它们时
ifort -c fort_subs.f90
icc main.cpp fort_subs.o

我收到错误

Undefined symbols for architecture x86_64:   "_for_stop_core", referenced from:
      _add1 in fort_subs.o ld: symbol(s) not found for architecture x86_64

当我用

编译它们时
icc -c main.cpp 
ifort -nofor-main fort_subs.f90 main.o

我收到错误

Undefined symbols for architecture x86_64:
  "___gxx_personality_v0", referenced from:
      Dwarf Exception Unwind Info (__eh_frame) in main.o
  "___intel_new_feature_proc_init", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64

那么为什么会出现这些错误以及如何解决这些错误呢?

我知道在ibm编译器中有一个选项“-lxlf90”告诉c编译器链接fortran库,它解决了“_for_stop_core”错误。在intel c编译器中是否有类似的选项?

1 个答案:

答案 0 :(得分:0)

似乎C不喜欢Fortran的STOP命令。如果要停止程序,可能需要考虑使用第二个值,如

subroutine add1(a,kill) bind(c)
   integer (c_int), intent(inout) :: a, kill
   kill = 0
   a = a+1
   if(a > 10) kill=1
end subroutine

main.cpp

//main.cpp
#include <stdio.h>
extern "C"{ void add1(int * a, int * kill); }

 int main(void){
  int a=20, kill;
  add1(&a, &kill);
  if(kill!=0) {
    printf("program halted due to a>10\n");
    return 0;
  }
  return 0;
}