编译一个混合GNU Fortran/ c++ MPI共享库
compiling a mixed GNU Fortran/C++ MPI shared library
我正试图将c++ MPI包装器编译为MPI Fortran库,但链接失败。使用
编译包装器。mpic++ -c my_wrapper.cc -o my_wrapper.o
my_wrapper。cc写道:
#include "mpi.h"
extern"C" {
void fortran_func_(int * comm,bool *do_init);
}
void c_func(MPI_Comm my_comm )
{
MPI_Fint fcomm;
fcomm = MPI_Comm_c2f(my_comm);
bool do_init = false;
fortran_func_(&fcomm, &do_init);
}
使用
编译库 MPI_LINK_FLAGS = $(shell mpic++ --showme:link)
mpif90 -shared my_wrapper.o $(FORTRAN-LIBS) $(MPI_LINK_FLAGS) -o my_libc++.a
链接错误如下:
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in my_wrapper.o
"std::ios_base::Init::~Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in my_wrapper.o
"vtable for __cxxabiv1::__class_type_info", referenced from:
typeinfo for MPI::Info in my_wrapper.o
typeinfo for MPI::Errhandler in my_wrapper.o
typeinfo for MPI::Win in my_wrapper.o
typeinfo for MPI::Comm_Null in my_wrapper.o
typeinfo for MPI::Group in my_wrapper.o
typeinfo for MPI::Request in my_wrapper.o
typeinfo for MPI::Status in my_wrapper.o
...
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for __cxxabiv1::__si_class_type_info", referenced from:
typeinfo for MPI::Intercomm in my_wrapper.o
typeinfo for MPI::Graphcomm in my_wrapper.o
typeinfo for MPI::Cartcomm in my_wrapper.o
typeinfo for MPI::Intracomm in my_wrapper.o
typeinfo for MPI::Comm in my_wrapper.o
typeinfo for MPI::Grequest in my_wrapper.o
typeinfo for MPI::Prequest in my_wrapper.o
...
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"operator delete[](void*)", referenced from:
MPI::Datatype::Get_contents(int, int, int, int*, long*, MPI::Datatype*) const in my_wrapper.o
MPI::Comm::Alltoallw(void const*, int const*, int const*, MPI::Datatype const*, void*, int const*, int const*, MPI::Datatype const*) const in my_wrapper.o
MPI::Intracomm::Create_cart(int, int const*, bool const*, bool) const in my_wrapper.o
MPI::Intracomm::Spawn_multiple(int, char const**, char const***, int const*, MPI::Info const*, int) in my_wrapper.o
MPI::Intracomm::Spawn_multiple(int, char const**, char const***, int const*, MPI::Info const*, int, int*) in my_wrapper.o
MPI::Cartcomm::Get_topo(int, int*, bool*, int*) const in my_wrapper.o
MPI::Cartcomm::Sub(bool const*) const in my_wrapper.o
...
"operator delete(void*)", referenced from:
MPI::Datatype::~Datatype() in my_wrapper.o
MPI::Datatype::~Datatype() in my_wrapper.o
MPI::Status::~Status() in my_wrapper.o
MPI::Status::~Status() in my_wrapper.o
MPI::Request::~Request() in my_wrapper.o
MPI::Request::~Request() in my_wrapper.o
MPI::Request::~Request() in my_wrapper.o
...
"operator new[](unsigned long)", referenced from:
MPI::Datatype::Get_contents(int, int, int, int*, long*, MPI::Datatype*) const in my_wrapper.o
MPI::Comm::Alltoallw(void const*, int const*, int const*, MPI::Datatype const*, void*, int const*, int const*, MPI::Datatype const*) const in my_wrapper.o
MPI::Intracomm::Create_cart(int, int const*, bool const*, bool) const in my_wrapper.o
MPI::Intracomm::convert_info_to_mpi_info(int, MPI::Info const*) in my_wrapper.o
MPI::Cartcomm::Get_topo(int, int*, bool*, int*) const in my_wrapper.o
MPI::Cartcomm::Sub(bool const*) const in my_wrapper.o
MPI::Cartcomm::Map(int, int const*, bool const*) const in my_wrapper.o
...
"operator new(unsigned long)", referenced from:
MPI::Intracomm::Clone() const in my_wrapper.o
MPI::Cartcomm::Clone() const in my_wrapper.o
MPI::Graphcomm::Clone() const in my_wrapper.o
MPI::Intercomm::Clone() const in my_wrapper.o
"___cxa_pure_virtual", referenced from:
vtable for MPI::Comm in my_wrapper.o
"___gxx_personality_v0", referenced from:
Dwarf Exception Unwind Info (__eh_frame) in my_wrapper.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
我找不到任何例子如何做这些事情(混合Fortran/c++与MPI),所以我在这里问,希望它将在某些时候对其他人有用。
注:
如果我尝试用mpic++
编译它:
MPIF_LINK_FLAGS = $(shell mpif90 --showme:link)
mpic++ -shared my_wrapper.o $(FORTRAN-LIBS) $(MPIF_LINK_FLAGS) -o $@
我错过了很多符号从$(FORTRAN-LIBS),我没有当我链接到mpif90
。所以我想我最好把那些缺失的库添加到Fortran链接器中。
我用Open MPI: 1.6
如果它重要。
EDIT1: 通过将这些添加到mpif90链接所有编译:
-L/opt/local/lib/gcc47/ -lstdc++
确实,缺少了一些标准的c++内容
您似乎正在使用FORTRAN链接器进行链接。它对c++标准库一无所知,所以所有的c++标准库(std::ios_base
的这些部分)都是"未定义的符号"。您需要修改您的link命令,以添加c++标准库。
由于复合语言既不完全是FORTRAN的,也不完全是c++的,所以FORTRAN和c++的链接器都不完全合适。您可能需要考虑直接使用ld
。在这种情况下,您必须列出c++标准库和FORTRAN标准库作为链接库。
相关文章:
- 使用 VS2015 在 Windows 10 上构建 Fortran .lib x64 位并将其链接到 C++
- 将 OR 逻辑运算符从 C++ 转换为 Fortran
- Fortran 和 C++ 的混合编程:Fortran 不能调用C++子程序
- 如何在C++中获取真实值精度 与Fortran相同(Pararel Studio XE编译器)
- 读取 C++ 中的 Fortran 数据类型
- 重新编译我们的FORTRAN代码并在C++中使用后,我们的system()或C_str()命令无法正常工作
- 使用C++和fortran构建R包,Mac
- 如何将C++17 stdc++fs库链接到混合语言(C++和Fortran)CMake项目
- 混合编程 - 包括C++标头到 Fortran
- 编译 Fortran 和C++程序并从英特尔编译器链接
- 与 MSVC 一起使用的 MinGW 的 Fortran 模块导致未解析的符号"__exmod_MOD_value"
- 将指向 1D Fortran 数组的指针传递给使用 C_LOC() 进行C++会导致垃圾值
- 将分配给C++数组传递给 Fortran 子例程
- 在 Fortran 中泛化特定声明类型的操作
- CPP -D 选项,用于预处理 Fortran 代码
- 通过矢量下标访问 Fortran 数组,相当于 cpp
- 如何将矢量从C 传递到Fortran
- 将字符串从 Fortran 传递到 c++
- 是否可以从C 调用FORTRAN接口
- C /FORTRAN项目由Visual Studio 2010/Intel 2013创建,将不会在Visual St