2

Fortran 서브 루틴을 호출하는 C 코드를 컴파일하려고하는데 항상 오류가 발생합니다. 나는 오류를컴파일 오류 : "_for_stop_core"을 찾을 수 없음

을 얻을

!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 

여기에 내가

ifort -c fort_subs.f90 
icc main.cpp fort_subs.o 

로를 컴파일 할 때 C 코드

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

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

입니다 : 여기

은 포트란 코드
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 컴파일러에는 "_for_stop_core"오류를 해결하는 fortran 라이브러리를 링크하도록 c 컴파일러에 알리는 "-lxlf90"옵션이 있습니다. 인텔 C 컴파일러에 비슷한 옵션이 있습니까?

답변

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; 
} 
+0

을 고려하는 것이 좋습니다 포트란 서브 루틴. 그리고 icc에게 Fortran 도서관을 연결시켜달라고 요청할 수 있어야합니다. 그 국기 알아? 나는 ibm 컴파일러에서'-lxlf90' 플래그를 사용하여 c 컴파일러에게 fortran 라이브러리를 연결하도록 알릴 수 있습니다. 또한 나는 실제 코드에서 많은 중지 문을 가지고 있으며, 수동으로 변경하는 것은 지루합니다. – xslittlegrass

+0

@xslittlegrass : 나는 그것을 고려하지 않았다고 생각한다. (추후 참고 용으로 질문에 그와 같은 세부 사항은 언급 할 가치가있다.) 컴파일러 옵션'-lifcore'를 추가하여 프로그램을 컴파일하고 실행할 수있었습니다. –

+0

그 - 리프 코어 무엇입니까? 내가 그것을 사용할 때 icc는 다음을 인식하지 못한다 : "ld : 라이브러리가 -lifcore에 없다" – xslittlegrass