не удается запустить mpicc в linux

#c #linux #parallel-processing #mpi #ubuntu-20.04

Вопрос:

Мой код отлично работал в Windows, теперь, когда я пытаюсь скомпилировать ubuntu 20.4; Я получаю эту ошибку; Я копирую часть ошибки, так как их много: после запуска : mpicc C.cpp -o C

    usr/bin/ld: C.cpp:(.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag] 0xb8): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_capacity(unsigned long)'
    /usr/bin/ld: C.cpp:(.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag] 0xc4): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_data() const'
    /usr/bin/ld: C.cpp:(.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag] 0xda): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_S_copy_chars(char*, char*, char*)'
    /usr/bin/ld: C.cpp:(.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag] 0xed): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_set_length(unsigned long)'
    /usr/bin/ld: C.cpp:(.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag] 0x10b): undefined reference to `__cxa_begin_catch'
    /usr/bin/ld: C.cpp:(.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag] 0x117): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_dispose()'
    /usr/bin/ld: C.cpp:(.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag] 0x11c): undefined reference to `__cxa_rethrow'
    /usr/bin/ld: C.cpp:(.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag] 0x128): undefined reference to `__cxa_end_catch'
    /usr/bin/ld: /tmp/ccNx3sbm.o: in function `__gnu_cxx::new_allocator<int>::deallocate(int*, unsigned long)':
    C.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE10deallocateEPim[_ZN9__gnu_cxx13new_allocatorIiE10deallocateEPim] 0x20): undefined reference to `operator delete(void*)'
    /usr/bin/ld: /tmp/ccNx3sbm.o: in function `__gnu_cxx::new_allocator<int>::allocate(unsigned long, void const*)':
    C.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE8allocateEmPKv[_ZN9__gnu_cxx13new_allocatorIiE8allocateEmPKv] 0x30): undefined reference to `std::__throw_bad_alloc()'
    /usr/bin/ld: C.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE8allocateEmPKv[_ZN9__gnu_cxx13new_allocatorIiE8allocateEmPKv] 0x40): undefined reference to `operator new(unsigned long)'
    /usr/bin/ld: /tmp/ccNx3sbm.o:(.data.rel.ro._ZTVN3MPI3WinE[_ZTVN3MPI3WinE] 0x48): undefined reference to `MPI::Win::Free()'
    /usr/bin/ld: /tmp/ccNx3sbm.o: in function `MPI::Intercomm::~Intercomm()':
    C.cpp:(.text._ZN3MPI9IntercommD0Ev[_ZN3MPI9IntercommD5Ev] 0x29): undefined reference to `operator delete(void*, unsigned long)'
    /usr/bin/ld: /tmp/ccNx3sbm.o: in function `MPI::Graphcomm::~Graphcomm()':
    C.cpp:(.text._ZN3MPI9GraphcommD0Ev[_ZN3MPI9GraphcommD5Ev] 0x29): undefined reference to `operator delete(void*, unsigned long)'
    /usr/bin/ld: /tmp/ccNx3sbm.o: in function `MPI::Cartcomm::~Cartcomm()':
 

когда я проверяю mpirun --version : я получаю это : mpirun (Open MPI) 4.0.3

Ответ №1:

Эта ошибка:

 usr/bin/ld: C.cpp:(.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag] 0xb8): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_capacity(unsigned long)'
    /usr/bin/ld: C.cpp:(.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag] 0xc4): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_data() const'
    /usr/bin/ld: C.cpp:(.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag] 0xda): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_S_copy_chars(char*, char*, char*)'
    /usr/bin/ld: C.cpp:(.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag] 0xed): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_set_length(unsigned long)'
    /usr/bin/ld: C.cpp:(.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag] 0x10b): undefined reference to `__cxa_begin_catch'
    /usr/bin/ld: C.cpp:(.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag] 0x117): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_dispose()'
    /usr/bin/ld: C.cpp:(.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag] 0x11c): undefined reference to `__cxa_rethrow'
    /usr/bin/ld: C.cpp:(.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag] 0x128): undefined reference to `__cxa_end_catch'
    /usr/bin/ld: /tmp/ccNx3sbm.o: in function `__gnu_cxx::new_allocator<int>::deallocate(int*, unsigned long)':
    C.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE10deallocateEPim[_ZN9__gnu_cxx13new_allocatorIiE10deallocateEPim] 0x20): undefined reference to `operator delete(void*)'
    /usr/bin/ld: /tmp/ccNx3sbm.o: in function `__gnu_cxx::new_allocator<int>::allocate(unsigned long, void const*)':
    C.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE8allocateEmPKv[_ZN9__gnu_cxx13new_allocatorIiE8allocateEmPKv] 0x30): undefined reference to `std::__throw_bad_alloc()'
    /usr/bin/ld: C.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE8allocateEmPKv[_ZN9__gnu_cxx13new_allocatorIiE8allocateEmPKv] 0x40): undefined reference to `operator new(unsigned long)'
    /usr/bin/ld: /tmp/ccNx3sbm.o:(.data.rel.ro._ZTVN3MPI3WinE[_ZTVN3MPI3WinE] 0x48): undefined reference to `MPI::Win::Free()'
    /usr/bin/ld: /tmp/ccNx3sbm.o: in function `MPI::Intercomm::~Intercomm()':
    C.cpp:(.text._ZN3MPI9IntercommD0Ev[_ZN3MPI9IntercommD5Ev] 0x29): undefined reference to `operator delete(void*, unsigned long)'
    /usr/bin/ld: /tmp/ccNx3sbm.o: in function `MPI::Graphcomm::~Graphcomm()':
    C.cpp:(.text._ZN3MPI9GraphcommD0Ev[_ZN3MPI9GraphcommD5Ev] 0x29): undefined reference to `operator delete(void*, unsigned long)'
    /usr/bin/ld: /tmp/ccNx3sbm.o: in function `MPI::Cartcomm::~Cartcomm()':
 

Потому что вы компилируете с помощью mpicc:

Компилирует и связывает программы MPI, написанные на C

но вы должны использовать в этом случае mpic

mpic — Открыть компилятор-оболочку MPI C