[英]How to call a fortran function from a c++ file in node-gyp?
I defined my fortran function in my "a.cpp" file as我在“a.cpp”文件中将我的 fortran 函数定义为
extern "C" double trial_func_(long *fsize, double* fvec);
I compiled my fortran code with:我编译了我的 Fortran 代码:
$ gfortran trial.f90 -c -o trial.o
I tried to build a library from the trial.o file using:我尝试使用以下命令从 trial.o 文件构建一个库:
$ ar rcs fortranlib.a trial.o
My binding.gyp file:我的 binding.gyp 文件:
{
"targets": [
{
"target_name": "rocket",
"cflags!": [ "-fno-exceptions"],
"cflags_cc!": [ "-fno-exceptions"],
"libraries": [ "C:\\fortranlib.a" ],
"sources": [
"./cpp/a.cpp",
"./cpp/index.cpp"
],
"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")"
],
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
}
]
}
I get the following errors when I use "node-gyp rebuild":使用“node-gyp rebuild”时出现以下错误:
a.obj : error LNK2019: unresolved external symbol trial_func_ referenced in function "double __cdecl fortranTrial(void)" (?fortranTrial@@YANXZ) a.obj : error LNK2019: 函数“double __cdecl fortranTrial(void)”中引用的未解析的外部符号trial_func_ (?fortranTrial@@YANXZ)
C:\\fortranlib.a : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64' C:\\fortranlib.a:警告 LNK4272:库机器类型“x86”与目标机器类型“x64”冲突
Any ideas how can I do this properly?任何想法我怎样才能正确地做到这一点?
Okay I got it.好的,我明白了。
I've been using gfortran 32-bit version, so I changed that to 64-bit.我一直在使用 gfortran 32 位版本,所以我将其更改为 64 位。
Then I used the .o file in "libraries" instead of .a file and that worked.然后我在“库”中使用了 .o 文件而不是 .a 文件并且有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.