ParMETIS:对“ParMETIS_V3_PartMeshKway”的未定义引用

ParMETIS: undefined reference to `ParMETIS_V3_PartMeshKway'

我已经构建并安装了 parmetis-4.0.3 并编写了一个简单的代码来测试它。但我收到一条错误消息:"undefined reference to `ParMETIS_V3_PartMeshKway'"

我的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;
}

我的 makefile 是:

ParMETIS_INCLUDES = ${cpp_libraries}/parmetis/include
METIS_INCLUDES = ${cpp_libraries}/metis/include

INCLUDES = -I${ParMETIS_INCLUDES} -I${METIS_INCLUDES}
LFLAGS =  -L${ParMETIS_INCLUDES} -L${METIS_INCLUDES}

CC = mpic++

parmetis_try: parmetis_try.cpp
    ${CC}  -Wall -g $(INCLUDES) -o parmetis_try.out parmetis_try.cpp $(LFLAGS)

clean:
    rm *.o *.out *~

如果我在命令行输入make,它会显示如下错误信息:

mpic++  -Wall -g -I/l/yangsong/Library/parmetis/include -I/l/yangsong/Library/metis/include -o parmetis_try.out parmetis_try.cpp -L/l/yangsong/Library/parmetis/include -L/l/yangsong/Library/metis/include
/tmp/ccmrGrI2.o: In function `main':
/l/yangsong/Simulation/VTURP/depreciated/parmetis_try/parmetis_try.cpp:85: undefined reference to `ParMETIS_V3_PartMeshKway'
collect2: error: ld returned 1 exit status
make: *** [parmetis_try] Error 1

一开始以为是我没有安装parmetis成功。但是如果我在.cpp文件中注释掉ParMETIS_V3_PartMeshKway这一行,它就会编译成功。另外,如果我输入 nm parmetis/lib/libparmetis.so | grep Kwa | grep Mes,它会显示:

000000000001b570 T libparmetis__CheckInputsPartMeshKway
0000000000013e80 T ParMETIS_V3_PartMeshKway

所以我认为parmetis安装成功了。想知道为什么我会收到此错误消息吗?

我不是编写 makefile 的专家,但我认为你的错误来自这个文件。如果我是对的,你忘了 link 对抗 metis。此外,-L 标志给出了库目录。我想 par_metis 库不在包含文件夹中。

我自己用 metis 重建了一个 makefile,它是这样工作的:

all: metis

main.o: main.cpp
   clang++ -Wall -I/usr/local/include -c main.cpp

metis: main.o
   clang++ -Wall main.o -o metis -L/usr/local/lib -lmetis

因为我不是 make 方面的专家,而且他们有很多错误源,所以我更喜欢 CMake 而不是 makefile。在这个 post 我举一个cmake的例子。用 parmetis 库替换 metis 应该很容易。 我希望这个答案可以帮助你,祝你在 metis 好运! :)