简体   繁体   中英

calling c functions from fortran, trouble with argc and argv

I'm very new to Fortran. Currently I'm writing (or trying to write) a fortran application which calls a C-library.

I've got a few things working so far but I'm stuck with the init-function from the library which expects argc and argv just to get the program name which is calling the function.

The C-library expects pointers to argc and argv:

void init(gint argc, gchar ***argv);

I have no idea how to express that ***argv in fortran. The other functions only need integers so I had no trouble using this skeleton for them:

interface
    subroutine init( argc, argv)
        ??
    end subroutine ee_init
end interface

call init( , )

您可能需要在C,init_fortran或类似函数中编写自己的包装器函数,这些函数可以从Fortran调用,并以您可以在Fortran中表达的方式获取参数,然后将它们转换为C init函数所期望的内容。

我建议使用模块ISO_C_BINDING并将指针传递给指针数组,如果我理解正确的话。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM