Metis 安装
Metis是一款开源的图划分、分割软件,在众多网络划分中有应用,其名字取自希腊智慧女神。其windows 安装已有很方便的教程,去知乎搜索就能搜到。为了在Linux环境中使用,可以通过 apt install 方式,也可以用源码安装,总的来说不复杂。
下载tar.gz 解压后
cd metis-5.1.0
make config --prefix=/home/metis #指定用户目录,避免权限问题
make
make install #安装到指定目录,头文件和lib文件
问题
C/CPP混合使用metis出现 undefined reference error
混用了c和cpp的代码经常出现undefined reference function error,就是CPP对函数名称做修饰,导致再使用原来C函数名调用就找不到,在C源文件使用extern C就可以避免CPP对函数名称做修饰。
举个例子 gcc 编译了 func.c 源文件,里面函数名就是func(),func.h头文件声明也是 func()名称,但是此时有个 cpp文件 include func.h 并且使用c++编译,链接了func.o,就会出现 undefined reference func() error,即使用 strings 和 nm 查看 func.o里面确实有func()函数,但是c++就是不认识,因为#include头文件里面对函数声明那里就以及重新修饰了该函数。
- 解决方法
在引用 metisbin.h时使用extern C关键字,注意 metis.h不会出现这个问题,因为其已经使用了extern C关键字。修改方式如下
#ifdef __cplusplus
extern "C" {
#endif
#include "metisbin.h"
#ifdef __cplusplus
}
#endif