未定义参考`ParMETIS_V3_PartMeshKway”

问题描述 投票:0回答:1

我用这个C ++代码

#include <iostream>
#include "parmetis.h"

int main(int argc, char **argv)
{

  MPI_Init(&argc, &argv);

  int np = 3;  int ne = 36;

  idx_t *elmdist = new idx_t[np+1];  for (int i=0; i<np+1; i++) {elmdist[i] = (i-1)*ne/np;} elmdist[np] = ne;

  idx_t *eptr = new idx_t[ne+1];   for (int i=0; i<ne+1; i++) {eptr[i] = (i-1)*3;}

  idx_t eind_[] = {13, 14, 15,
           13, 16, 17,
           2, 17, 6,
           4, 15, 10,
           13, 15, 19,
           13, 17, 18,
           13, 19, 16,
           13, 18, 14,
           1, 5, 16,
           3, 9, 14,
           7, 8, 18,
           11, 12, 19,
           1, 20, 12,
           3, 21, 8,
           7, 18, 23,
           11, 19, 22,
           2, 23, 17,
           4, 22, 15,
           14, 25, 15,
           16, 24, 17,
           15, 22, 19,
           17, 23, 18,
           1, 16, 20,
           3, 14, 21,
           5, 24, 16,
           9, 25, 14,
           16, 19, 20,
           14, 18, 21,
           6, 17, 24,
           10, 15, 25,
           5, 6, 24,
           9, 10, 25,
           8, 21, 18,
           12, 20, 19,
           2, 7, 23,
           4, 11, 22};
  idx_t *eind = eind_;

  idx_t *elmwgt = NULL;

  idx_t wgtflag_[] = {0};
  idx_t *wgtflag = wgtflag_;

  idx_t numflag_[] = {0};
  idx_t *numflag = numflag_;

  idx_t ncon_[] = {1};
  idx_t *ncon = ncon_;

  idx_t ncommonnodes_[] = {2};
  idx_t *ncommonnodes = ncommonnodes_;

  idx_t nparts_[] = {np};
  idx_t *nparts = nparts_;

  real_t *tpwgts = new real_t[np*ncon[0]]; for(int i=0; i<np*ncon[0]; i++) {tpwgts[i] = 1.0/np;}

  real_t ubvec_[] = {1.05};
  real_t *ubvec = ubvec_;

  idx_t options_[] ={0, 0, 0};
  idx_t *options =options_;

  idx_t *edgecut=NULL;

  idx_t *part=NULL;

  MPI_Comm *comm=NULL;

  ParMETIS_V3_PartMeshKway(elmdist, eptr, eind, elmwgt, wgtflag, numflag, ncon, ncommonnodes, nparts, tpwgts, ubvec, options, edgecut, part, comm);

  MPI_Finalize();
  return 0;
}

在allmet我插入来自梅蒂斯人和parmetis所有文件。尝试使用的openmpi使用g ++编译器编译:

mpicxx -I path/allmet/include -L path/allmet/lib par.cpp

我得到的错误:

undefined reference to `ParMETIS_V3_PartMeshKway'

通过CMake:

cmake_minimum_required(VERSION 2.8.9)
project (MetisTest)
find_package(MPI)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
include_directories("path/allmet/include")
link_directories("path/allmet/lib")
add_executable(metisTest par.cpp)
target_link_libraries(metisTest ${MPI_C_LIBRARIES})

我有:

undefined reference to `ParMETIS_V3_PartMeshKway'
in function `MPI::Intracomm::Intracomm()':
undefined reference to `MPI::Comm::Comm()'

和许多其他人,以便我能做些什么?梅蒂斯工作完美,但与parmetis我不能做任何事情。 Ubuntu的18.10,GCC 8.2.0。

c++ mpi openmpi metis
1个回答
0
投票

您还需要对自身Parmetis链接:

target_link_libraries(metisTest ${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES} ${PARMETIS_LIBS})

请注意:

link_directories("path/allmet/lib")

无关的链接。如果你仍然想使用命令行,您需要:

mpicxx -Ipath/allmet/include -Lpath/allmet/lib -lparmetis -lmetis par.cpp
© www.soinside.com 2019 - 2024. All rights reserved.