我正在尝试编译调用 fortran 子例程的 ac 代码,但总是出错。
这是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 编译器中是否有类似的选项?