我有这个已关闭的特定主题问题,试图从 Fortran 的 libcurl 简单 API 调用 C: https ://stackoverflow.com/questions/44891188/calling-libcurl-from-fortran-2008
根据评论的建议,我仍然收到有关如何从 Fortran 正确调用 C 指针和 C 函数的错误。
这里的代码不多,但主要问题是警告:
dl2.f08:11.23:
type, bind(C) :: CURL
1
Warning: Derived type 'curl' with BIND(C) attribute at (1) is empty, and may be inaccessible by the C companion processor
dl2.f08:14.27:
和错误:
call curl_easy_setopt(curl, CURLOPT_URL_VAL, "http://example.com")
1
Error: More actual than formal arguments in procedure call at (1)
dl2.f08:48.35:
这是我的最小示例:
module fcurl
! This is the simple C code I am trying to call from Fortran
!
! CURL *curl = curl_easy_init();
! if(curl) {
! CURLcode res;
! curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
! res = curl_easy_perform(curl);
! curl_easy_cleanup(curl);
! }
use, intrinsic :: iso_c_binding
implicit none
type, bind(C) :: CURL
end type CURL
type, bind(C) :: CURLcode
end type CURLcode
type, bind(C) :: CURLOPT_URL
end type CURLOPT_URL
interface
subroutine curl_easy_init() bind(C, name="curl_easy_init")
end subroutine curl_easy_init
end interface
interface
subroutine curl_easy_setopt() bind(C, name="curl_easy_setopt")
end subroutine curl_easy_setopt
end interface
interface
subroutine curl_easy_perform() bind(C, name="curl_easy_perform")
end subroutine curl_easy_perform
end interface
interface
subroutine curl_easy_cleanup() bind(C, name="curl_easy_cleanup")
end subroutine curl_easy_cleanup
end interface
end module fcurl
program mycurl
use fcurl
type(CURL) :: curl
type(CURLcode) :: res
type(CURLOPT_URL) :: CURLOPT_URL_VAL
call curl_easy_init(curl)
call curl_easy_setopt(curl, CURLOPT_URL_VAL, "http://example.com")
call curl_easy_perform(res, curl)
print *, res
call curl_easy_cleanup(curl)
end program mycurl
还引用了这个: