[英]Mixed languages link error with meson build system (Fortran/C++)
I am encountering issues when trying to compile fortran code using meson build system on an HPC cluster.我在 HPC 集群上尝试使用介子构建系统编译 fortran 代码时遇到问题。
On the cluster, I am using Intel compiler suite.在集群上,我使用的是 Intel 编译器套件。 The meson compile
command aborts at the linking step with: meson compile
命令在链接步骤中终止:
ld: /usr/bin/../lib64/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
ninja: build stopped: subcommand failed.
The interesting thing is that the link command issued by meson is something like this: icpc -o main main.p/somefile.o...
, so it is using Intel's C++ compiler to link my fortran code.有意思的是meson发出的链接命令是这样的: icpc -o main main.p/somefile.o...
,所以是用Intel的C++编译器链接我的fortran代码。 I tried to use the exact same command line, replacing icpc with ifort and adding -lstdc++
.我尝试使用完全相同的命令行,将icpc替换为ifort并添加-lstdc++
。 That actually worked.这确实奏效了。
So, I wonder, is there a way to force Meson to link my code with ifort
, instead of icpc
?所以,我想知道,有没有办法强制 Meson 将我的代码与ifort
而不是icpc
链接? Or, should I do something else?或者,我应该做点别的吗?
I am afrad I cannot share the code at this moment.恐怕我现在不能分享代码。 But, I'm open to showing bits and pieces of the meson.build file(s), if needed.但是,如果需要,我愿意展示 meson.build 文件的点点滴滴。
The codebase consists of fortran source and a CMake C++ subproject;代码库由 fortran 源码和一个 CMake C++ 子项目组成; Essentially, the C++ subproject is a wrapper for OpenCV image plotting functions.本质上,C++ 子项目是 OpenCV 图像绘图函数的包装器。 This is why I needed to add -lstdc++
to my successful manual link command above.这就是为什么我需要将-lstdc++
添加到上面成功的手动链接命令中。
Meson version: 0.55.3介子版本:0.55.3
Intel Fortran compiler: ifort (IFORT) 19.1.3.304 20200925 Intel Fortran 编译器:ifort (IFORT) 19.1.3.304 20200925
Intel C++ compiler: icpc (ICC) 19.1.3.304 20200925英特尔 C++ 编译器:icpc (ICC) 19.1.3.304 20200925
The code is MPI parallelised.代码是 MPI 并行化的。
The same code compiles well with GNU compilers v10 on a normal workstation.同样的代码在普通工作站上用 GNU 编译器 v10 编译得很好。
Meson is not going to do any hand-holding when it comes to mixing languages.在混合语言方面,介子不会做任何手把手的工作。 Here is what I found out works for Intel compilers:这是我发现适用于英特尔编译器的内容:
fc=meson.get_compiler('fortran')
# cxx=meson.get_compiler('cpp')
...
if (fc.get_id() == 'intel')
#if (cxx.get_id() == 'intel')
...
add_global_link_arguments('-cxxlib',language : 'fortran')
add_global_link_arguments('-nofor_main', language : 'cpp')
endif
...
executable('myprog','myprog.f90', ..., link_language : 'fortran')
#executable('myprog','myprog.f90',...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.