我有一个Fortran子例程,我想从C++程序中调用它.它需要很长的浮点参数列表并使用iso_c_binding内部模块:
subroutine parasolve ( ...... ) bind (c, name='c_parasolve')
use,intrinsic :: iso_c_binding
implicit none
....
Run Code Online (Sandbox Code Playgroud)
基于我所读到的内容,我理解我需要使用C++的"extern"命令来定义外部函数,然后再调用它.我尝试了两种方法.首先:
extern "C" void c_parasolve( .... );
Run Code Online (Sandbox Code Playgroud)
在编译时返回"字符串常量之前的预期unqualified-id",而第二个:
extern void c_parasolve( .... );
Run Code Online (Sandbox Code Playgroud)
编译得很好但无法链接"未定义引用'c_parasolve(....)'"并且ld返回1.
我正在编译:
g++ -c main.cpp
Run Code Online (Sandbox Code Playgroud)
等等
gfortran -ffree-form -std=f2003 -c parasolve.f03
Run Code Online (Sandbox Code Playgroud)
让他们进入.o ELF然后尝试链接:
g++ main.o otherfiles.o parasolve.o -lgfortran
Run Code Online (Sandbox Code Playgroud)
调用此Fortran函数的正确方法是什么?
我遇到了无法在 Common Lisp (SBCL 2.3.4) 中解释的奇怪行为。考虑以下测试用例:
(defclass class-a ()
((foobar :initarg :foobar
:accessor foobar
:initform '(foo bar))))
(defclass class-b ()
((something :initarg :something
:accessor something)))
(defvar *instance-a* (make-instance 'class-a))
(defvar *instance-b* (make-instance 'class-b :something *instance-a*))
Run Code Online (Sandbox Code Playgroud)
如果我instance-b在 REPL 中检查,我可以看到变量something已被设置:
CL-USER> (slot-value *instance-b* 'something)
#<CLASS-A {7007C70C53}>
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试创建这些对象的一个简单向量,由于缺乏更好的术语,该对象似乎会“失去跟踪”其绑定:
CL-USER> (slot-value (elt #(*instance-b*) 0) 'something)
; Debugger entered on #<SB-PCL::MISSING-SLOT SOMETHING {7008E5A1E3}>
When attempting to read the slot's value (slot-value), the slot
SOMETHING is missing from the object *INSTANCE-B*.
[Condition …Run Code Online (Sandbox Code Playgroud)