Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Compiler errors 编译错误:"_对于“U停止”核心;找不到_Compiler Errors_Fortran_Icc_Intel Fortran_Fortran Iso C Binding - Fatal编程技术网

Compiler errors 编译错误:"_对于“U停止”核心;找不到

Compiler errors 编译错误:"_对于“U停止”核心;找不到,compiler-errors,fortran,icc,intel-fortran,fortran-iso-c-binding,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 e

我试图编译一个调用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
我犯了一个错误

当我用

icc -c main.cpp 
ifort -nofor-main fort_subs.f90 main.o
我犯了一个错误

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


我知道在ibm编译器中有一个选项“-lxlf90”,它告诉c编译器链接fortran库,从而解决了“\u for\u stop\u core”错误。英特尔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;
}
//main.cpp
#包括
外部“C”{void add1(int*a,int*kill);}
内部主(空){
int a=20,kill;
添加1(&a和&kill);
if(kill!=0){
printf(“程序因>10而停止”);
返回0;
}
返回0;
}

在我的真实代码中,stop不是fortran子例程的最后一条语句。它应该能够要求icc引入fortran库来链接。你知道那面旗子吗?我知道在ibm编译器中,可以使用
-lxlf90
标志来告诉c编译器链接fortran库。另外,我在实际代码中有很多stop语句,手工更改它们是乏味的。@xslittlegrass:我明白了,我想我没有考虑过这一点(供将来参考:在问题中提及类似的小细节可能是值得的)。我能够通过添加编译器选项
-lifcore
来编译和运行程序。那是什么-lifcore?当我使用时,icc不承认:“ld:library not found for-lifcore”您使用的是哪个版本的
icc
?在哪个站台?我在Ubuntu linux上有
ICC13.1.3
,它没有给我任何问题。OSX10.8上的ICC14.0.0版
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
#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;
}