gpt4 book ai didi

compiler-errors - 编译错误: “_for_stop_core” not found

转载 作者:行者123 更新时间:2023-12-02 10:43:04 24 4
gpt4 key购买 nike

我正在尝试编译一个调用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编译器中有类似的选项吗?

最佳答案

看来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;
}

关于compiler-errors - 编译错误: “_for_stop_core” not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19363928/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com