c++ - 使用 IGRAPH 面向对象编程

标签 c++ c igraph

我的 igraph 库非常适合 C 语言的代码。

但是,当我尝试用 C++ 编译代码时,我遇到了 undefined reference 问题。有些功能有效,有些功能无效。根据我的研究,我相信缺少的是包含“igraph.hpp”。虽然,我不知道如何安装这些文件。

我正在尝试编译以下示例程序:

#include <iostream>
#include <igraph.h>

using namespace std;

int main() {

  igraph_t g;
  FILE *ifile;
  int i;
  igraph_sparsemat_t temp;

  ifile=fopen("karate.gml", "r");
  if (ifile==0) printf("erro");

  igraph_read_graph_gml(&g, ifile);
  fclose(ifile);

  i=igraph_get_sparsemat(&g, &temp);

  return 0;

}

我正在使用以下命令编译程序:

g++ teste.cc -I/usr/local/include/igraph -L/usr/local/lib -ligraph -o teste

但是,出现了这个错误:

teste.cc:(.text+0x77): referência indefinida para `igraph_get_sparsemat(igraph_s const*, igraph_sparsemat_t*)'
collect2: error: ld returned 1 exit status

谁能帮帮我?

最佳答案

就这样

extern "C" {
   #include <igraph.h>
}

c++ 编译器会混淆函数名称,因此在库中搜索该函数时将找不到它,如果您这样做,则在 igraph.h 中声明的每个函数都将具有防止名称混淆的 c 链接。

关于c++ - 使用 IGRAPH 面向对象编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28078282/

相关文章:

c - 如何在文件中查找不重复的字符串

c - 二叉树的中序后继

R中igraph中的R倒数边

r - 使用R中的igraph计算开放三角形顶点中节点的出现次数

c++ - boost 累加器示例不编译

c++ - 模板中的默认参数 -> 模板参数涉及模板参数

c++ - 在内核外使用 CUDA printf 打印设备变量

c++ - uintptr_t 存储的是指针的地址还是它的值?

c - 错误 : cuda_runtime. h:没有那个文件或目录

python - igraph:有属性时如何使用add_edges?